Source for file pclzip.lib.php

Documentation is available at pclzip.lib.php

  1. <?php
  2. // --------------------------------------------------------------------------------
  3. // PhpConcept Library - Zip Module 2.5
  4. // --------------------------------------------------------------------------------
  5. // License GNU/LGPL - Vincent Blavet - March 2006
  6. // http://www.phpconcept.net
  7. // --------------------------------------------------------------------------------
  8. //
  9. // Presentation :
  10. //   PclZip is a PHP library that manage ZIP archives.
  11. //   So far tests show that archives generated by PclZip are readable by
  12. //   WinZip application and other tools.
  13. //
  14. // Description :
  15. //   See readme.txt and http://www.phpconcept.net
  16. //
  17. // Warning :
  18. //   This library and the associated files are non commercial, non professional
  19. //   work.
  20. //   It should not have unexpected results. However if any damage is caused by
  21. //   this software the author can not be responsible.
  22. //   The use of this software is at the risk of the user.
  23. //
  24. // --------------------------------------------------------------------------------
  25. // $Id: pclzip.lib.php,v 1.44 2006/03/08 21:23:59 vblavet Exp $
  26. // --------------------------------------------------------------------------------
  27.  
  28.   // ----- Constants
  29.   define'PCLZIP_READ_BLOCK_SIZE'2048 );
  30.   
  31.   // ----- File list separator
  32.   // In version 1.x of PclZip, the separator for file list is a space
  33.   // (which is not a very smart choice, specifically for windows paths !).
  34.   // A better separator should be a comma (,). This constant gives you the
  35.   // abilty to change that.
  36.   // However notice that changing this value, may have impact on existing
  37.   // scripts, using space separated filenames.
  38.   // Recommanded values for compatibility with older versions :
  39.   //define( 'PCLZIP_SEPARATOR', ' ' );
  40.   // Recommanded values for smart separation of filenames.
  41.   define'PCLZIP_SEPARATOR'',' );
  42.  
  43.   // ----- Error configuration
  44.   // 0 : PclZip Class integrated error handling
  45.   // 1 : PclError external library error handling. By enabling this
  46.   //     you must ensure that you have included PclError library.
  47.   // [2,...] : reserved for futur use
  48.   define'PCLZIP_ERROR_EXTERNAL');
  49.  
  50.   // ----- Optional static temporary directory
  51.   //       By default temporary files are generated in the script current
  52.   //       path.
  53.   //       If defined :
  54.   //       - MUST BE terminated by a '/'.
  55.   //       - MUST be a valid, already created directory
  56.   //       Samples :
  57.   // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
  58.   // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
  59.   define'PCLZIP_TEMPORARY_DIR'mamboCore::get('rootPath').'/media/' );
  60.  
  61. // --------------------------------------------------------------------------------
  62. // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  63. // --------------------------------------------------------------------------------
  64.  
  65.   // ----- Global variables
  66.   $g_pclzip_version "2.5";
  67.  
  68.   // ----- Error codes
  69.   //   -1 : Unable to open file in binary write mode
  70.   //   -2 : Unable to open file in binary read mode
  71.   //   -3 : Invalid parameters
  72.   //   -4 : File does not exist
  73.   //   -5 : Filename is too long (max. 255)
  74.   //   -6 : Not a valid zip file
  75.   //   -7 : Invalid extracted file size
  76.   //   -8 : Unable to create directory
  77.   //   -9 : Invalid archive extension
  78.   //  -10 : Invalid archive format
  79.   //  -11 : Unable to delete file (unlink)
  80.   //  -12 : Unable to rename file (rename)
  81.   //  -13 : Invalid header checksum
  82.   //  -14 : Invalid archive size
  83.   define'PCLZIP_ERR_USER_ABORTED');
  84.   define'PCLZIP_ERR_NO_ERROR');
  85.   define'PCLZIP_ERR_WRITE_OPEN_FAIL'-);
  86.   define'PCLZIP_ERR_READ_OPEN_FAIL'-);
  87.   define'PCLZIP_ERR_INVALID_PARAMETER'-);
  88.   define'PCLZIP_ERR_MISSING_FILE'-);
  89.   define'PCLZIP_ERR_FILENAME_TOO_LONG'-);
  90.   define'PCLZIP_ERR_INVALID_ZIP'-);
  91.   define'PCLZIP_ERR_BAD_EXTRACTED_FILE'-);
  92.   define'PCLZIP_ERR_DIR_CREATE_FAIL'-);
  93.   define'PCLZIP_ERR_BAD_EXTENSION'-);
  94.   define'PCLZIP_ERR_BAD_FORMAT'-10 );
  95.   define'PCLZIP_ERR_DELETE_FILE_FAIL'-11 );
  96.   define'PCLZIP_ERR_RENAME_FILE_FAIL'-12 );
  97.   define'PCLZIP_ERR_BAD_CHECKSUM'-13 );
  98.   define'PCLZIP_ERR_INVALID_ARCHIVE_ZIP'-14 );
  99.   define'PCLZIP_ERR_MISSING_OPTION_VALUE'-15 );
  100.   define'PCLZIP_ERR_INVALID_OPTION_VALUE'-16 );
  101.   define'PCLZIP_ERR_ALREADY_A_DIRECTORY'-17 );
  102.   define'PCLZIP_ERR_UNSUPPORTED_COMPRESSION'-18 );
  103.   define'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'-19 );
  104.   define'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'-20 );
  105.   define'PCLZIP_ERR_DIRECTORY_RESTRICTION'-21 );
  106.  
  107.   // ----- Options values
  108.   define'PCLZIP_OPT_PATH'77001 );
  109.   define'PCLZIP_OPT_ADD_PATH'77002 );
  110.   define'PCLZIP_OPT_REMOVE_PATH'77003 );
  111.   define'PCLZIP_OPT_REMOVE_ALL_PATH'77004 );
  112.   define'PCLZIP_OPT_SET_CHMOD'77005 );
  113.   define'PCLZIP_OPT_EXTRACT_AS_STRING'77006 );
  114.   define'PCLZIP_OPT_NO_COMPRESSION'77007 );
  115.   define'PCLZIP_OPT_BY_NAME'77008 );
  116.   define'PCLZIP_OPT_BY_INDEX'77009 );
  117.   define'PCLZIP_OPT_BY_EREG'77010 );
  118.   define'PCLZIP_OPT_BY_PREG'77011 );
  119.   define'PCLZIP_OPT_COMMENT'77012 );
  120.   define'PCLZIP_OPT_ADD_COMMENT'77013 );
  121.   define'PCLZIP_OPT_PREPEND_COMMENT'77014 );
  122.   define'PCLZIP_OPT_EXTRACT_IN_OUTPUT'77015 );
  123.   define'PCLZIP_OPT_REPLACE_NEWER'77016 );
  124.   define'PCLZIP_OPT_STOP_ON_ERROR'77017 );
  125.   // Having big trouble with crypt. Need to multiply 2 long int
  126.   // which is not correctly supported by PHP ...
  127.   //define( 'PCLZIP_OPT_CRYPT', 77018 );
  128.   define'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION'77019 );
  129.   
  130.   // ----- File description attributes
  131.   define'PCLZIP_ATT_FILE_NAME'79001 );
  132.   define'PCLZIP_ATT_FILE_NEW_SHORT_NAME'79002 );
  133.   define'PCLZIP_ATT_FILE_NEW_FULL_NAME'79003 );
  134.  
  135.   // ----- Call backs values
  136.   define'PCLZIP_CB_PRE_EXTRACT'78001 );
  137.   define'PCLZIP_CB_POST_EXTRACT'78002 );
  138.   define'PCLZIP_CB_PRE_ADD'78003 );
  139.   define'PCLZIP_CB_POST_ADD'78004 );
  140.   /* For futur use
  141.   define( 'PCLZIP_CB_PRE_LIST', 78005 );
  142.   define( 'PCLZIP_CB_POST_LIST', 78006 );
  143.   define( 'PCLZIP_CB_PRE_DELETE', 78007 );
  144.   define( 'PCLZIP_CB_POST_DELETE', 78008 );
  145.   */
  146.  
  147.   // --------------------------------------------------------------------------------
  148.   // Class : PclZip
  149.   // Description :
  150.   //   PclZip is the class that represent a Zip archive.
  151.   //   The public methods allow the manipulation of the archive.
  152.   // Attributes :
  153.   //   Attributes must not be accessed directly.
  154.   // Methods :
  155.   //   PclZip() : Object creator
  156.   //   create() : Creates the Zip archive
  157.   //   listContent() : List the content of the Zip archive
  158.   //   extract() : Extract the content of the archive
  159.   //   properties() : List the properties of the archive
  160.   // --------------------------------------------------------------------------------
  161.   class PclZip
  162.   {
  163.     // ----- Filename of the zip file
  164.     var $zipname = '';
  165.  
  166.     // ----- File descriptor of the zip file
  167.     var $zip_fd = 0;
  168.  
  169.     // ----- Internal error handling
  170.     var $error_code = 1;
  171.     var $error_string = '';
  172.     
  173.     // ----- Current status of the magic_quotes_runtime
  174.     // This value store the php configuration for magic_quotes
  175.     // The class can then disable the magic_quotes and reset it after
  176.     var $magic_quotes_status;
  177.  
  178.   // --------------------------------------------------------------------------------
  179.   // Function : PclZip()
  180.   // Description :
  181.   //   Creates a PclZip object and set the name of the associated Zip archive
  182.   //   filename.
  183.   //   Note that no real action is taken, if the archive does not exist it is not
  184.   //   created. Use create() for that.
  185.   // --------------------------------------------------------------------------------
  186.   function PclZip($p_zipname)
  187.   {
  188.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");
  189.  
  190.     // ----- Tests the zlib
  191.     if (!function_exists('gzopen'))
  192.     {
  193.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");
  194.       die('Abort '.basename(__FILE__).' : Missing zlib extensions');
  195.     }
  196.  
  197.     // ----- Set the attributes
  198.     $this->zipname = $p_zipname;
  199.     $this->zip_fd = 0;
  200.     $this->magic_quotes_status = -1;
  201.  
  202.     // ----- Return
  203.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);
  204.     return;
  205.   }
  206.   // --------------------------------------------------------------------------------
  207.  
  208.   // --------------------------------------------------------------------------------
  209.   // Function :
  210.   //   create($p_filelist, $p_add_dir="", $p_remove_dir="")
  211.   //   create($p_filelist, $p_option, $p_option_value, ...)
  212.   // Description :
  213.   //   This method supports two different synopsis. The first one is historical.
  214.   //   This method creates a Zip Archive. The Zip file is created in the
  215.   //   filesystem. The files and directories indicated in $p_filelist
  216.   //   are added in the archive. See the parameters description for the
  217.   //   supported format of $p_filelist.
  218.   //   When a directory is in the list, the directory and its content is added
  219.   //   in the archive.
  220.   //   In this synopsis, the function takes an optional variable list of
  221.   //   options. See bellow the supported options.
  222.   // Parameters :
  223.   //   $p_filelist : An array containing file or directory names, or
  224.   //                 a string containing one filename or one directory name, or
  225.   //                 a string containing a list of filenames and/or directory
  226.   //                 names separated by spaces.
  227.   //   $p_add_dir : A path to add before the real path of the archived file,
  228.   //                in order to have it memorized in the archive.
  229.   //   $p_remove_dir : A path to remove from the real path of the file to archive,
  230.   //                   in order to have a shorter path memorized in the archive.
  231.   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
  232.   //                   is removed first, before $p_add_dir is added.
  233.   // Options :
  234.   //   PCLZIP_OPT_ADD_PATH :
  235.   //   PCLZIP_OPT_REMOVE_PATH :
  236.   //   PCLZIP_OPT_REMOVE_ALL_PATH :
  237.   //   PCLZIP_OPT_COMMENT :
  238.   //   PCLZIP_CB_PRE_ADD :
  239.   //   PCLZIP_CB_POST_ADD :
  240.   // Return Values :
  241.   //   0 on failure,
  242.   //   The list of the added files, with a status of the add action.
  243.   //   (see PclZip::listContent() for list entry format)
  244.   // --------------------------------------------------------------------------------
  245.   function create($p_filelist)
  246.   {
  247.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");
  248.     $v_result=1;
  249.  
  250.     // ----- Reset the error handler
  251.     $this->privErrorReset();
  252.  
  253.     // ----- Set default values
  254.     $v_options array();
  255.     $v_options[PCLZIP_OPT_NO_COMPRESSIONFALSE;
  256.  
  257.     // ----- Look for variable options arguments
  258.     $v_size func_num_args();
  259.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  260.  
  261.     // ----- Look for arguments
  262.     if ($v_size 1{
  263.       // ----- Get the arguments
  264.       $v_arg_list func_get_args();
  265.  
  266.       // ----- Remove from the options list the first argument
  267.       array_shift($v_arg_list);
  268.       $v_size--;
  269.  
  270.       // ----- Look for first arg
  271.       if ((is_integer($v_arg_list[0])) && ($v_arg_list[077000)) {
  272.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
  273.  
  274.         // ----- Parse the options
  275.         $v_result $this->privParseOptions($v_arg_list$v_size$v_options,
  276.                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  277.                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  278.                                                    PCLZIP_OPT_ADD_PATH => 'optional',
  279.                                                    PCLZIP_CB_PRE_ADD => 'optional',
  280.                                                    PCLZIP_CB_POST_ADD => 'optional',
  281.                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
  282.                                                    PCLZIP_OPT_COMMENT => 'optional'
  283.                                                    //, PCLZIP_OPT_CRYPT => 'optional'
  284.                                              ));
  285.         if ($v_result != 1{
  286.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  287.           return 0;
  288.         }
  289.       }
  290.  
  291.       // ----- Look for 2 args
  292.       // Here we need to support the first historic synopsis of the
  293.       // method.
  294.       else {
  295.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  296.  
  297.         // ----- Get the first argument
  298.         $v_options[PCLZIP_OPT_ADD_PATH$v_arg_list[0];
  299.  
  300.         // ----- Look for the optional second argument
  301.         if ($v_size == 2{
  302.           $v_options[PCLZIP_OPT_REMOVE_PATH$v_arg_list[1];
  303.         }
  304.         else if ($v_size 2{
  305.                                "Invalid number / type of arguments");
  306.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  307.           return 0;
  308.         }
  309.       }
  310.     }
  311.  
  312.     // ----- Init
  313.     $v_string_list array();
  314.     $v_att_list array();
  315.     $v_filedescr_list array();
  316.     $p_result_list array();
  317.     
  318.     // ----- Look if the $p_filelist is really an array
  319.     if (is_array($p_filelist)) {
  320.     
  321.       // ----- Look if the first element is also an array
  322.       //       This will mean that this is a file description entry
  323.       if (isset($p_filelist[0]&& is_array($p_filelist[0])) {
  324.         $v_att_list $p_filelist;
  325.       }
  326.       
  327.       // ----- The list is a list of string names
  328.       else {
  329.         $v_string_list $p_filelist;
  330.       }
  331.     }
  332.  
  333.     // ----- Look if the $p_filelist is a string
  334.     else if (is_string($p_filelist)) {
  335.       // ----- Create a list from the string
  336.       $v_string_list explode(PCLZIP_SEPARATOR$p_filelist);
  337.     }
  338.  
  339.     // ----- Invalid variable type for $p_filelist
  340.     else {
  341.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid variable type p_filelist");
  342.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  343.       return 0;
  344.     }
  345.     
  346.     // ----- Reformat the string list
  347.     if (sizeof($v_string_list!= 0{
  348.       foreach ($v_string_list as $v_string{
  349.         if ($v_string != ''{
  350.           $v_att_list[][PCLZIP_ATT_FILE_NAME$v_string;
  351.         }
  352.         else {
  353.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Ignore an empty filename");
  354.         }
  355.       }
  356.     }
  357.     
  358.     // ----- For each file in the list check the attributes
  359.     $v_supported_attributes
  360.     = array PCLZIP_ATT_FILE_NAME => 'mandatory'
  361.              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  362.              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  363.                         );
  364.     foreach ($v_att_list as $v_entry{
  365.       $v_result $this->privFileDescrParseAtt($v_entry,
  366.                                                $v_filedescr_list[],
  367.                                                $v_options,
  368.                                                $v_supported_attributes);
  369.       if ($v_result != 1{
  370.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  371.         return 0;
  372.       }
  373.     }
  374.  
  375.     // ----- Expand the filelist (expand directories)
  376.     $v_result $this->privFileDescrExpand($v_filedescr_list$v_options);
  377.     if ($v_result != 1{
  378.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  379.       return 0;
  380.     }
  381.  
  382.     // ----- Call the create fct
  383.     $v_result $this->privCreate($v_filedescr_list$p_result_list$v_options);
  384.     if ($v_result != 1{
  385.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  386.       return 0;
  387.     }
  388.  
  389.     // ----- Return
  390.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
  391.     return $p_result_list;
  392.   }
  393.   // --------------------------------------------------------------------------------
  394.  
  395.   // --------------------------------------------------------------------------------
  396.   // Function :
  397.   //   add($p_filelist, $p_add_dir="", $p_remove_dir="")
  398.   //   add($p_filelist, $p_option, $p_option_value, ...)
  399.   // Description :
  400.   //   This method supports two synopsis. The first one is historical.
  401.   //   This methods add the list of files in an existing archive.
  402.   //   If a file with the same name already exists, it is added at the end of the
  403.   //   archive, the first one is still present.
  404.   //   If the archive does not exist, it is created.
  405.   // Parameters :
  406.   //   $p_filelist : An array containing file or directory names, or
  407.   //                 a string containing one filename or one directory name, or
  408.   //                 a string containing a list of filenames and/or directory
  409.   //                 names separated by spaces.
  410.   //   $p_add_dir : A path to add before the real path of the archived file,
  411.   //                in order to have it memorized in the archive.
  412.   //   $p_remove_dir : A path to remove from the real path of the file to archive,
  413.   //                   in order to have a shorter path memorized in the archive.
  414.   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
  415.   //                   is removed first, before $p_add_dir is added.
  416.   // Options :
  417.   //   PCLZIP_OPT_ADD_PATH :
  418.   //   PCLZIP_OPT_REMOVE_PATH :
  419.   //   PCLZIP_OPT_REMOVE_ALL_PATH :
  420.   //   PCLZIP_OPT_COMMENT :
  421.   //   PCLZIP_OPT_ADD_COMMENT :
  422.   //   PCLZIP_OPT_PREPEND_COMMENT :
  423.   //   PCLZIP_CB_PRE_ADD :
  424.   //   PCLZIP_CB_POST_ADD :
  425.   // Return Values :
  426.   //   0 on failure,
  427.   //   The list of the added files, with a status of the add action.
  428.   //   (see PclZip::listContent() for list entry format)
  429.   // --------------------------------------------------------------------------------
  430.   function add($p_filelist)
  431.   {
  432.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");
  433.     $v_result=1;
  434.  
  435.     // ----- Reset the error handler
  436.     $this->privErrorReset();
  437.  
  438.     // ----- Set default values
  439.     $v_options array();
  440.     $v_options[PCLZIP_OPT_NO_COMPRESSIONFALSE;
  441.  
  442.     // ----- Look for variable options arguments
  443.     $v_size func_num_args();
  444.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  445.  
  446.     // ----- Look for arguments
  447.     if ($v_size 1{
  448.       // ----- Get the arguments
  449.       $v_arg_list func_get_args();
  450.  
  451.       // ----- Remove form the options list the first argument
  452.       array_shift($v_arg_list);
  453.       $v_size--;
  454.  
  455.       // ----- Look for first arg
  456.       if ((is_integer($v_arg_list[0])) && ($v_arg_list[077000)) {
  457.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
  458.  
  459.         // ----- Parse the options
  460.         $v_result $this->privParseOptions($v_arg_list$v_size$v_options,
  461.                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  462.                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  463.                                                    PCLZIP_OPT_ADD_PATH => 'optional',
  464.                                                    PCLZIP_CB_PRE_ADD => 'optional',
  465.                                                    PCLZIP_CB_POST_ADD => 'optional',
  466.                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
  467.                                                    PCLZIP_OPT_COMMENT => 'optional',
  468.                                                    PCLZIP_OPT_ADD_COMMENT => 'optional',
  469.                                                    PCLZIP_OPT_PREPEND_COMMENT => 'optional'
  470.                                                    //, PCLZIP_OPT_CRYPT => 'optional'
  471.                                                    ));
  472.         if ($v_result != 1{
  473.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  474.           return 0;
  475.         }
  476.       }
  477.  
  478.       // ----- Look for 2 args
  479.       // Here we need to support the first historic synopsis of the
  480.       // method.
  481.       else {
  482.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  483.  
  484.         // ----- Get the first argument
  485.         $v_options[PCLZIP_OPT_ADD_PATH$v_add_path $v_arg_list[0];
  486.  
  487.         // ----- Look for the optional second argument
  488.         if ($v_size == 2{
  489.           $v_options[PCLZIP_OPT_REMOVE_PATH$v_arg_list[1];
  490.         }
  491.         else if ($v_size 2{
  492.           // ----- Error log
  493.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid number / type of arguments");
  494.  
  495.           // ----- Return
  496.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  497.           return 0;
  498.         }
  499.       }
  500.     }
  501.  
  502.     // ----- Init
  503.     $v_string_list array();
  504.     $v_att_list array();
  505.     $v_filedescr_list array();
  506.     $p_result_list array();
  507.     
  508.     // ----- Look if the $p_filelist is really an array
  509.     if (is_array($p_filelist)) {
  510.     
  511.       // ----- Look if the first element is also an array
  512.       //       This will mean that this is a file description entry
  513.       if (isset($p_filelist[0]&& is_array($p_filelist[0])) {
  514.         $v_att_list $p_filelist;
  515.       }
  516.       
  517.       // ----- The list is a list of string names
  518.       else {
  519.         $v_string_list $p_filelist;
  520.       }
  521.     }
  522.  
  523.     // ----- Look if the $p_filelist is a string
  524.     else if (is_string($p_filelist)) {
  525.       // ----- Create a list from the string
  526.       $v_string_list explode(PCLZIP_SEPARATOR$p_filelist);
  527.     }
  528.  
  529.     // ----- Invalid variable type for $p_filelist
  530.     else {
  531.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid variable type '".gettype($p_filelist)."' for p_filelist");
  532.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  533.       return 0;
  534.     }
  535.     
  536.     // ----- Reformat the string list
  537.     if (sizeof($v_string_list!= 0{
  538.       foreach ($v_string_list as $v_string{
  539.         $v_att_list[][PCLZIP_ATT_FILE_NAME$v_string;
  540.       }
  541.     }
  542.     
  543.     // ----- For each file in the list check the attributes
  544.     $v_supported_attributes
  545.     = array PCLZIP_ATT_FILE_NAME => 'mandatory'
  546.              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  547.              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  548.                         );
  549.     foreach ($v_att_list as $v_entry{
  550.       $v_result $this->privFileDescrParseAtt($v_entry,
  551.                                                $v_filedescr_list[],
  552.                                                $v_options,
  553.                                                $v_supported_attributes);
  554.       if ($v_result != 1{
  555.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  556.         return 0;
  557.       }
  558.     }
  559.  
  560.     // ----- Expand the filelist (expand directories)
  561.     $v_result $this->privFileDescrExpand($v_filedescr_list$v_options);
  562.     if ($v_result != 1{
  563.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  564.       return 0;
  565.     }
  566.  
  567.     // ----- Call the create fct
  568.     $v_result $this->privAdd($v_filedescr_list$p_result_list$v_options);
  569.     if ($v_result != 1{
  570.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  571.       return 0;
  572.     }
  573.  
  574.     // ----- Return
  575.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
  576.     return $p_result_list;
  577.   }
  578.   // --------------------------------------------------------------------------------
  579.  
  580.   // --------------------------------------------------------------------------------
  581.   // Function : listContent()
  582.   // Description :
  583.   //   This public method, gives the list of the files and directories, with their
  584.   //   properties.
  585.   //   The properties of each entries in the list are (used also in other functions) :
  586.   //     filename : Name of the file. For a create or add action it is the filename
  587.   //                given by the user. For an extract function it is the filename
  588.   //                of the extracted file.
  589.   //     stored_filename : Name of the file / directory stored in the archive.
  590.   //     size : Size of the stored file.
  591.   //     compressed_size : Size of the file's data compressed in the archive
  592.   //                       (without the headers overhead)
  593.   //     mtime : Last known modification date of the file (UNIX timestamp)
  594.   //     comment : Comment associated with the file
  595.   //     folder : true | false
  596.   //     index : index of the file in the archive
  597.   //     status : status of the action (depending of the action) :
  598.   //              Values are :
  599.   //                ok : OK !
  600.   //                filtered : the file / dir is not extracted (filtered by user)
  601.   //                already_a_directory : the file can not be extracted because a
  602.   //                                      directory with the same name already exists
  603.   //                write_protected : the file can not be extracted because a file
  604.   //                                  with the same name already exists and is
  605.   //                                  write protected
  606.   //                newer_exist : the file was not extracted because a newer file exists
  607.   //                path_creation_fail : the file is not extracted because the folder
  608.   //                                     does not exists and can not be created
  609.   //                write_error : the file was not extracted because there was a
  610.   //                              error while writing the file
  611.   //                read_error : the file was not extracted because there was a error
  612.   //                             while reading the file
  613.   //                invalid_header : the file was not extracted because of an archive
  614.   //                                 format error (bad file header)
  615.   //   Note that each time a method can continue operating when there
  616.   //   is an action error on a file, the error is only logged in the file status.
  617.   // Return Values :
  618.   //   0 on an unrecoverable failure,
  619.   //   The list of the files in the archive.
  620.   // --------------------------------------------------------------------------------
  621.   function listContent()
  622.   {
  623.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");
  624.     $v_result=1;
  625.  
  626.     // ----- Reset the error handler
  627.     $this->privErrorReset();
  628.  
  629.     // ----- Check archive
  630.     if (!$this->privCheckFormat()) {
  631.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  632.       return(0);
  633.     }
  634.  
  635.     // ----- Call the extracting fct
  636.     $p_list array();
  637.     if (($v_result $this->privList($p_list)) != 1)
  638.     {
  639.       unset($p_list);
  640.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  641.       return(0);
  642.     }
  643.  
  644.     // ----- Return
  645.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  646.     return $p_list;
  647.   }
  648.   // --------------------------------------------------------------------------------
  649.  
  650.   // --------------------------------------------------------------------------------
  651.   // Function :
  652.   //   extract($p_path="./", $p_remove_path="")
  653.   //   extract([$p_option, $p_option_value, ...])
  654.   // Description :
  655.   //   This method supports two synopsis. The first one is historical.
  656.   //   This method extract all the files / directories from the archive to the
  657.   //   folder indicated in $p_path.
  658.   //   If you want to ignore the 'root' part of path of the memorized files
  659.   //   you can indicate this in the optional $p_remove_path parameter.
  660.   //   By default, if a newer file with the same name already exists, the
  661.   //   file is not extracted.
  662.   //
  663.   //   If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
  664.   //   are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
  665.   //   at the end of the path value of PCLZIP_OPT_PATH.
  666.   // Parameters :
  667.   //   $p_path : Path where the files and directories are to be extracted
  668.   //   $p_remove_path : First part ('root' part) of the memorized path
  669.   //                    (if any similar) to remove while extracting.
  670.   // Options :
  671.   //   PCLZIP_OPT_PATH :
  672.   //   PCLZIP_OPT_ADD_PATH :
  673.   //   PCLZIP_OPT_REMOVE_PATH :
  674.   //   PCLZIP_OPT_REMOVE_ALL_PATH :
  675.   //   PCLZIP_CB_PRE_EXTRACT :
  676.   //   PCLZIP_CB_POST_EXTRACT :
  677.   // Return Values :
  678.   //   0 or a negative value on failure,
  679.   //   The list of the extracted files, with a status of the action.
  680.   //   (see PclZip::listContent() for list entry format)
  681.   // --------------------------------------------------------------------------------
  682.   function extract()
  683.   {
  684.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
  685.     $v_result=1;
  686.  
  687.     // ----- Reset the error handler
  688.     $this->privErrorReset();
  689.  
  690.     // ----- Check archive
  691.     if (!$this->privCheckFormat()) {
  692.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  693.       return(0);
  694.     }
  695.  
  696.     // ----- Set default values
  697.     $v_options array();
  698. //    $v_path = "./";
  699.     $v_path '';
  700.     $v_remove_path "";
  701.     $v_remove_all_path false;
  702.  
  703.     // ----- Look for variable options arguments
  704.     $v_size func_num_args();
  705.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  706.  
  707.     // ----- Default values for option
  708.     $v_options[PCLZIP_OPT_EXTRACT_AS_STRINGFALSE;
  709.  
  710.     // ----- Look for arguments
  711.     if ($v_size 0{
  712.       // ----- Get the arguments
  713.       $v_arg_list func_get_args();
  714.  
  715.       // ----- Look for first arg
  716.       if ((is_integer($v_arg_list[0])) && ($v_arg_list[077000)) {
  717.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
  718.  
  719.         // ----- Parse the options
  720.         $v_result $this->privParseOptions($v_arg_list$v_size$v_options,
  721.                                             array (PCLZIP_OPT_PATH => 'optional',
  722.                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
  723.                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  724.                                                    PCLZIP_OPT_ADD_PATH => 'optional',
  725.                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
  726.                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
  727.                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
  728.                                                    PCLZIP_OPT_BY_NAME => 'optional',
  729.                                                    PCLZIP_OPT_BY_EREG => 'optional',
  730.                                                    PCLZIP_OPT_BY_PREG => 'optional',
  731.                                                    PCLZIP_OPT_BY_INDEX => 'optional',
  732.                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  733.                                                    PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
  734.                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
  735.                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  736.                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
  737.                                                     ));
  738.         if ($v_result != 1{
  739.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  740.           return 0;
  741.         }
  742.  
  743.         // ----- Set the arguments
  744.         if (isset($v_options[PCLZIP_OPT_PATH])) {
  745.           $v_path $v_options[PCLZIP_OPT_PATH];
  746.         }
  747.         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  748.           $v_remove_path $v_options[PCLZIP_OPT_REMOVE_PATH];
  749.         }
  750.         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  751.           $v_remove_all_path $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  752.         }
  753.         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  754.           // ----- Check for '/' in last path char
  755.           if ((strlen($v_path0&& (substr($v_path-1!= '/')) {
  756.             $v_path .= '/';
  757.           }
  758.           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  759.         }
  760.       }
  761.  
  762.       // ----- Look for 2 args
  763.       // Here we need to support the first historic synopsis of the
  764.       // method.
  765.       else {
  766.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  767.  
  768.         // ----- Get the first argument
  769.         $v_path $v_arg_list[0];
  770.  
  771.         // ----- Look for the optional second argument
  772.         if ($v_size == 2{
  773.           $v_remove_path $v_arg_list[1];
  774.         }
  775.         else if ($v_size 2{
  776.           // ----- Error log
  777.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid number / type of arguments");
  778.  
  779.           // ----- Return
  780.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  781.           return 0;
  782.         }
  783.       }
  784.     }
  785.  
  786.     // ----- Trace
  787.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
  788.  
  789.     // ----- Call the extracting fct
  790.     $p_list array();
  791.     $v_result $this->privExtractByRule($p_list$v_path$v_remove_path,
  792.                                          $v_remove_all_path$v_options);
  793.     if ($v_result 1{
  794.       unset($p_list);
  795.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  796.       return(0);
  797.     }
  798.  
  799.     // ----- Return
  800.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  801.     return $p_list;
  802.   }
  803.   // --------------------------------------------------------------------------------
  804.  
  805.  
  806.   // --------------------------------------------------------------------------------
  807.   // Function :
  808.   //   extractByIndex($p_index, $p_path="./", $p_remove_path="")
  809.   //   extractByIndex($p_index, [$p_option, $p_option_value, ...])
  810.   // Description :
  811.   //   This method supports two synopsis. The first one is historical.
  812.   //   This method is doing a partial extract of the archive.
  813.   //   The extracted files or folders are identified by their index in the
  814.   //   archive (from 0 to n).
  815.   //   Note that if the index identify a folder, only the folder entry is
  816.   //   extracted, not all the files included in the archive.
  817.   // Parameters :
  818.   //   $p_index : A single index (integer) or a string of indexes of files to
  819.   //              extract. The form of the string is "0,4-6,8-12" with only numbers
  820.   //              and '-' for range or ',' to separate ranges. No spaces or ';'
  821.   //              are allowed.
  822.   //   $p_path : Path where the files and directories are to be extracted
  823.   //   $p_remove_path : First part ('root' part) of the memorized path
  824.   //                    (if any similar) to remove while extracting.
  825.   // Options :
  826.   //   PCLZIP_OPT_PATH :
  827.   //   PCLZIP_OPT_ADD_PATH :
  828.   //   PCLZIP_OPT_REMOVE_PATH :
  829.   //   PCLZIP_OPT_REMOVE_ALL_PATH :
  830.   //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
  831.   //     not as files.
  832.   //     The resulting content is in a new field 'content' in the file
  833.   //     structure.
  834.   //     This option must be used alone (any other options are ignored).
  835.   //   PCLZIP_CB_PRE_EXTRACT :
  836.   //   PCLZIP_CB_POST_EXTRACT :
  837.   // Return Values :
  838.   //   0 on failure,
  839.   //   The list of the extracted files, with a status of the action.
  840.   //   (see PclZip::listContent() for list entry format)
  841.   // --------------------------------------------------------------------------------
  842.   //function extractByIndex($p_index, options...)
  843.   function extractByIndex($p_index)
  844.   {
  845.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");
  846.     $v_result=1;
  847.  
  848.     // ----- Reset the error handler
  849.     $this->privErrorReset();
  850.  
  851.     // ----- Check archive
  852.     if (!$this->privCheckFormat()) {
  853.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  854.       return(0);
  855.     }
  856.  
  857.     // ----- Set default values
  858.     $v_options array();
  859. //    $v_path = "./";
  860.     $v_path '';
  861.     $v_remove_path "";
  862.     $v_remove_all_path false;
  863.  
  864.     // ----- Look for variable options arguments
  865.     $v_size func_num_args();
  866.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  867.  
  868.     // ----- Default values for option
  869.     $v_options[PCLZIP_OPT_EXTRACT_AS_STRINGFALSE;
  870.  
  871.     // ----- Look for arguments
  872.     if ($v_size 1{
  873.       // ----- Get the arguments
  874.       $v_arg_list func_get_args();
  875.  
  876.       // ----- Remove form the options list the first argument
  877.       array_shift($v_arg_list);
  878.       $v_size--;
  879.  
  880.       // ----- Look for first arg
  881.       if ((is_integer($v_arg_list[0])) && ($v_arg_list[077000)) {
  882.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
  883.  
  884.         // ----- Parse the options
  885.         $v_result $this->privParseOptions($v_arg_list$v_size$v_options,
  886.                                             array (PCLZIP_OPT_PATH => 'optional',
  887.                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
  888.                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  889.                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  890.                                                    PCLZIP_OPT_ADD_PATH => 'optional',
  891.                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
  892.                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
  893.                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
  894.                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
  895.                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  896.                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional'
  897.                                                    ));
  898.         if ($v_result != 1{
  899.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  900.           return 0;
  901.         }
  902.  
  903.         // ----- Set the arguments
  904.         if (isset($v_options[PCLZIP_OPT_PATH])) {
  905.           $v_path $v_options[PCLZIP_OPT_PATH];
  906.         }
  907.         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  908.           $v_remove_path $v_options[PCLZIP_OPT_REMOVE_PATH];
  909.         }
  910.         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  911.           $v_remove_all_path $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  912.         }
  913.         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  914.           // ----- Check for '/' in last path char
  915.           if ((strlen($v_path0&& (substr($v_path-1!= '/')) {
  916.             $v_path .= '/';
  917.           }
  918.           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  919.         }
  920.         if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
  921.           $v_options[PCLZIP_OPT_EXTRACT_AS_STRINGFALSE;
  922.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");
  923.         }
  924.         else {
  925.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");
  926.         }
  927.       }
  928.  
  929.       // ----- Look for 2 args
  930.       // Here we need to support the first historic synopsis of the
  931.       // method.
  932.       else {
  933.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  934.  
  935.         // ----- Get the first argument
  936.         $v_path $v_arg_list[0];
  937.  
  938.         // ----- Look for the optional second argument
  939.         if ($v_size == 2{
  940.           $v_remove_path $v_arg_list[1];
  941.         }
  942.         else if ($v_size 2{
  943.           // ----- Error log
  944.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid number / type of arguments");
  945.  
  946.           // ----- Return
  947.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  948.           return 0;
  949.         }
  950.       }
  951.     }
  952.  
  953.     // ----- Trace
  954.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
  955.  
  956.     // ----- Trick
  957.     // Here I want to reuse extractByRule(), so I need to parse the $p_index
  958.     // with privParseOptions()
  959.     $v_arg_trick array (PCLZIP_OPT_BY_INDEX$p_index);
  960.     $v_options_trick array();
  961.     $v_result $this->privParseOptions($v_arg_tricksizeof($v_arg_trick)$v_options_trick,
  962.                                         array (PCLZIP_OPT_BY_INDEX => 'optional' ));
  963.     if ($v_result != 1{
  964.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  965.         return 0;
  966.     }
  967.     $v_options[PCLZIP_OPT_BY_INDEX$v_options_trick[PCLZIP_OPT_BY_INDEX];
  968.  
  969.     // ----- Call the extracting fct
  970.     if (($v_result $this->privExtractByRule($p_list$v_path$v_remove_path$v_remove_all_path$v_options)) 1{
  971.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  972.         return(0);
  973.     }
  974.  
  975.     // ----- Return
  976.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  977.     return $p_list;
  978.   }
  979.   // --------------------------------------------------------------------------------
  980.  
  981.   // --------------------------------------------------------------------------------
  982.   // Function :
  983.   //   delete([$p_option, $p_option_value, ...])
  984.   // Description :
  985.   //   This method removes files from the archive.
  986.   //   If no parameters are given, then all the archive is emptied.
  987.   // Parameters :
  988.   //   None or optional arguments.
  989.   // Options :
  990.   //   PCLZIP_OPT_BY_INDEX :
  991.   //   PCLZIP_OPT_BY_NAME :
  992.   //   PCLZIP_OPT_BY_EREG : 
  993.   //   PCLZIP_OPT_BY_PREG :
  994.   // Return Values :
  995.   //   0 on failure,
  996.   //   The list of the files which are still present in the archive.
  997.   //   (see PclZip::listContent() for list entry format)
  998.   // --------------------------------------------------------------------------------
  999.   function delete()
  1000.   {
  1001.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");
  1002.     $v_result=1;
  1003.  
  1004.     // ----- Reset the error handler
  1005.     $this->privErrorReset();
  1006.  
  1007.     // ----- Check archive
  1008.     if (!$this->privCheckFormat()) {
  1009.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  1010.       return(0);
  1011.     }
  1012.  
  1013.     // ----- Set default values
  1014.     $v_options array();
  1015.  
  1016.     // ----- Look for variable options arguments
  1017.     $v_size func_num_args();
  1018.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  1019.  
  1020.     // ----- Look for arguments
  1021.     if ($v_size 0{
  1022.       // ----- Get the arguments
  1023.       $v_arg_list func_get_args();
  1024.  
  1025.       // ----- Parse the options
  1026.       $v_result $this->privParseOptions($v_arg_list$v_size$v_options,
  1027.                                         array (PCLZIP_OPT_BY_NAME => 'optional',
  1028.                                                PCLZIP_OPT_BY_EREG => 'optional',
  1029.                                                PCLZIP_OPT_BY_PREG => 'optional',
  1030.                                                PCLZIP_OPT_BY_INDEX => 'optional' ));
  1031.       if ($v_result != 1{
  1032.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  1033.           return 0;
  1034.       }
  1035.     }
  1036.  
  1037.     // ----- Magic quotes trick
  1038.     $this->privDisableMagicQuotes();
  1039.  
  1040.     // ----- Call the delete fct
  1041.     $v_list array();
  1042.     if (($v_result $this->privDeleteByRule($v_list$v_options)) != 1{
  1043.       $this->privSwapBackMagicQuotes();
  1044.       unset($v_list);
  1045.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  1046.       return(0);
  1047.     }
  1048.  
  1049.     // ----- Magic quotes trick
  1050.     $this->privSwapBackMagicQuotes();
  1051.  
  1052.     // ----- Return
  1053.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);
  1054.     return $v_list;
  1055.   }
  1056.   // --------------------------------------------------------------------------------
  1057.  
  1058.   // --------------------------------------------------------------------------------
  1059.   // Function : deleteByIndex()
  1060.   // Description :
  1061.   //   ***** Deprecated *****
  1062.   //   delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
  1063.   // --------------------------------------------------------------------------------
  1064.   function deleteByIndex($p_index)
  1065.   {
  1066.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");
  1067.     
  1068.     $p_list $this->delete(PCLZIP_OPT_BY_INDEX$p_index);
  1069.  
  1070.     // ----- Return
  1071.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  1072.     return $p_list;
  1073.   }
  1074.   // --------------------------------------------------------------------------------
  1075.  
  1076.   // --------------------------------------------------------------------------------
  1077.   // Function : properties()
  1078.   // Description :
  1079.   //   This method gives the properties of the archive.
  1080.   //   The properties are :
  1081.   //     nb : Number of files in the archive
  1082.   //     comment : Comment associated with the archive file
  1083.   //     status : not_exist, ok
  1084.   // Parameters :
  1085.   //   None
  1086.   // Return Values :
  1087.   //   0 on failure,
  1088.   //   An array with the archive properties.
  1089.   // --------------------------------------------------------------------------------
  1090.   function properties()
  1091.   {
  1092.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");
  1093.  
  1094.     // ----- Reset the error handler
  1095.     $this->privErrorReset();
  1096.  
  1097.     // ----- Magic quotes trick
  1098.     $this->privDisableMagicQuotes();
  1099.  
  1100.     // ----- Check archive
  1101.     if (!$this->privCheckFormat()) {
  1102.       $this->privSwapBackMagicQuotes();
  1103.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  1104.       return(0);
  1105.     }
  1106.  
  1107.     // ----- Default properties
  1108.     $v_prop array();
  1109.     $v_prop['comment''';
  1110.     $v_prop['nb'0;
  1111.     $v_prop['status''not_exist';
  1112.  
  1113.     // ----- Look if file exists
  1114.     if (@is_file($this->zipname))
  1115.     {
  1116.       // ----- Open the zip file
  1117.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  1118.       if (($this->zip_fd = @fopen($this->zipname'rb')) == 0)
  1119.       {
  1120.         $this->privSwapBackMagicQuotes();
  1121.         
  1122.         // ----- Error log
  1123.         PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  1124.  
  1125.         // ----- Return
  1126.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);
  1127.         return 0;
  1128.       }
  1129.  
  1130.       // ----- Read the central directory informations
  1131.       $v_central_dir array();
  1132.       if (($v_result $this->privReadEndCentralDir($v_central_dir)) != 1)
  1133.       {
  1134.         $this->privSwapBackMagicQuotes();
  1135.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  1136.         return 0;
  1137.       }
  1138.  
  1139.       // ----- Close the zip file
  1140.       $this->privCloseFd();
  1141.  
  1142.       // ----- Set the user attributes
  1143.       $v_prop['comment'$v_central_dir['comment'];
  1144.       $v_prop['nb'$v_central_dir['entries'];
  1145.       $v_prop['status''ok';
  1146.     }
  1147.  
  1148.     // ----- Magic quotes trick
  1149.     $this->privSwapBackMagicQuotes();
  1150.  
  1151.     // ----- Return
  1152.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
  1153.     return $v_prop;
  1154.   }
  1155.   // --------------------------------------------------------------------------------
  1156.  
  1157.   // --------------------------------------------------------------------------------
  1158.   // Function : duplicate()
  1159.   // Description :
  1160.   //   This method creates an archive by copying the content of an other one. If
  1161.   //   the archive already exist, it is replaced by the new one without any warning.
  1162.   // Parameters :
  1163.   //   $p_archive : The filename of a valid archive, or
  1164.   //                a valid PclZip object.
  1165.   // Return Values :
  1166.   //   1 on success.
  1167.   //   0 or a negative value on error (error code).
  1168.   // --------------------------------------------------------------------------------
  1169.   function duplicate($p_archive)
  1170.   {
  1171.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
  1172.     $v_result 1;
  1173.  
  1174.     // ----- Reset the error handler
  1175.     $this->privErrorReset();
  1176.  
  1177.     // ----- Look if the $p_archive is a PclZip object
  1178.     if ((is_object($p_archive)) && (get_class($p_archive== 'pclzip'))
  1179.     {
  1180.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");
  1181.  
  1182.       // ----- Duplicate the archive
  1183.       $v_result $this->privDuplicate($p_archive->zipname);
  1184.     }
  1185.  
  1186.     // ----- Look if the $p_archive is a string (so a filename)
  1187.     else if (is_string($p_archive))
  1188.     {
  1189.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");
  1190.  
  1191.       // ----- Check that $p_archive is a valid zip file
  1192.       // TBC : Should also check the archive format
  1193.       if (!is_file($p_archive)) {
  1194.         // ----- Error log
  1195.         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE"No file with filename '".$p_archive."'");
  1196.         $v_result PCLZIP_ERR_MISSING_FILE;
  1197.       }
  1198.       else {
  1199.         // ----- Duplicate the archive
  1200.         $v_result $this->privDuplicate($p_archive);
  1201.       }
  1202.     }
  1203.  
  1204.     // ----- Invalid variable
  1205.     else
  1206.     {
  1207.       // ----- Error log
  1208.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid variable type p_archive_to_add");
  1209.       $v_result PCLZIP_ERR_INVALID_PARAMETER;
  1210.     }
  1211.  
  1212.     // ----- Return
  1213.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1214.     return $v_result;
  1215.   }
  1216.   // --------------------------------------------------------------------------------
  1217.  
  1218.   // --------------------------------------------------------------------------------
  1219.   // Function : merge()
  1220.   // Description :
  1221.   //   This method merge the $p_archive_to_add archive at the end of the current
  1222.   //   one ($this).
  1223.   //   If the archive ($this) does not exist, the merge becomes a duplicate.
  1224.   //   If the $p_archive_to_add archive does not exist, the merge is a success.
  1225.   // Parameters :
  1226.   //   $p_archive_to_add : It can be directly the filename of a valid zip archive,
  1227.   //                       or a PclZip object archive.
  1228.   // Return Values :
  1229.   //   1 on success,
  1230.   //   0 or negative values on error (see below).
  1231.   // --------------------------------------------------------------------------------
  1232.   function merge($p_archive_to_add)
  1233.   {
  1234.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
  1235.     $v_result 1;
  1236.  
  1237.     // ----- Reset the error handler
  1238.     $this->privErrorReset();
  1239.  
  1240.     // ----- Check archive
  1241.     if (!$this->privCheckFormat()) {
  1242.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  1243.       return(0);
  1244.     }
  1245.  
  1246.     // ----- Look if the $p_archive_to_add is a PclZip object
  1247.     if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add== 'pclzip'))
  1248.     {
  1249.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");
  1250.  
  1251.       // ----- Merge the archive
  1252.       $v_result $this->privMerge($p_archive_to_add);
  1253.     }
  1254.  
  1255.     // ----- Look if the $p_archive_to_add is a string (so a filename)
  1256.     else if (is_string($p_archive_to_add))
  1257.     {
  1258.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");
  1259.  
  1260.       // ----- Create a temporary archive
  1261.       $v_object_archive new PclZip($p_archive_to_add);
  1262.  
  1263.       // ----- Merge the archive
  1264.       $v_result $this->privMerge($v_object_archive);
  1265.     }
  1266.  
  1267.     // ----- Invalid variable
  1268.     else
  1269.     {
  1270.       // ----- Error log
  1271.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid variable type p_archive_to_add");
  1272.       $v_result PCLZIP_ERR_INVALID_PARAMETER;
  1273.     }
  1274.  
  1275.     // ----- Return
  1276.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1277.     return $v_result;
  1278.   }
  1279.   // --------------------------------------------------------------------------------
  1280.  
  1281.  
  1282.  
  1283.   // --------------------------------------------------------------------------------
  1284.   // Function : errorCode()
  1285.   // Description :
  1286.   // Parameters :
  1287.   // --------------------------------------------------------------------------------
  1288.   function errorCode()
  1289.   {
  1290.     if (PCLZIP_ERROR_EXTERNAL == 1{
  1291.       return(PclErrorCode());
  1292.     }
  1293.     else {
  1294.       return($this->error_code);
  1295.     }
  1296.   }
  1297.   // --------------------------------------------------------------------------------
  1298.  
  1299.   // --------------------------------------------------------------------------------
  1300.   // Function : errorName()
  1301.   // Description :
  1302.   // Parameters :
  1303.   // --------------------------------------------------------------------------------
  1304.   function errorName($p_with_code=false)
  1305.   {
  1306.     $v_name array PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
  1307.                       PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
  1308.                       PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
  1309.                       PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
  1310.                       PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
  1311.                       PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
  1312.                       PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
  1313.                       PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
  1314.                       PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
  1315.                       PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
  1316.                       PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
  1317.                       PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
  1318.                       PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
  1319.                       PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
  1320.                       PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
  1321.                       PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
  1322.                       PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
  1323.                       PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
  1324.                       PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
  1325.                       ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
  1326.                       ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
  1327.                     );
  1328.  
  1329.     if (isset($v_name[$this->error_code])) {
  1330.       $v_value $v_name[$this->error_code];
  1331.     }
  1332.     else {
  1333.       $v_value 'NoName';
  1334.     }
  1335.  
  1336.     if ($p_with_code{
  1337.       return($v_value.' ('.$this->error_code.')');
  1338.     }
  1339.     else {
  1340.       return($v_value);
  1341.     }
  1342.   }
  1343.   // --------------------------------------------------------------------------------
  1344.  
  1345.   // --------------------------------------------------------------------------------
  1346.   // Function : errorInfo()
  1347.   // Description :
  1348.   // Parameters :
  1349.   // --------------------------------------------------------------------------------
  1350.   function errorInfo($p_full=false)
  1351.   {
  1352.     if (PCLZIP_ERROR_EXTERNAL == 1{
  1353.       return(PclErrorString());
  1354.     }
  1355.     else {
  1356.       if ($p_full{
  1357.         return($this->errorName(true)." : ".$this->error_string);
  1358.       }
  1359.       else {
  1360.         return($this->error_string." [code ".$this->error_code."]");
  1361.       }
  1362.     }
  1363.   }
  1364.   // --------------------------------------------------------------------------------
  1365.  
  1366.  
  1367. // --------------------------------------------------------------------------------
  1368. // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
  1369. // *****                                                        *****
  1370. // *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY       *****
  1371. // --------------------------------------------------------------------------------
  1372.  
  1373.  
  1374.  
  1375.   // --------------------------------------------------------------------------------
  1376.   // Function : privCheckFormat()
  1377.   // Description :
  1378.   //   This method check that the archive exists and is a valid zip archive.
  1379.   //   Several level of check exists. (futur)
  1380.   // Parameters :
  1381.   //   $p_level : Level of check. Default 0.
  1382.   //              0 : Check the first bytes (magic codes) (default value))
  1383.   //              1 : 0 + Check the central directory (futur)
  1384.   //              2 : 1 + Check each file header (futur)
  1385.   // Return Values :
  1386.   //   true on success,
  1387.   //   false on error, the error code is set.
  1388.   // --------------------------------------------------------------------------------
  1389.   function privCheckFormat($p_level=0)
  1390.   {
  1391.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
  1392.     $v_result true;
  1393.  
  1394.     // ----- Reset the file system cache
  1395.     clearstatcache();
  1396.  
  1397.     // ----- Reset the error handler
  1398.     $this->privErrorReset();
  1399.  
  1400.     // ----- Look if the file exits
  1401.     if (!is_file($this->zipname)) {
  1402.       // ----- Error log
  1403.       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE"Missing archive file '".$this->zipname."'");
  1404.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
  1405.       return(false);
  1406.     }
  1407.  
  1408.     // ----- Check that the file is readeable
  1409.     if (!is_readable($this->zipname)) {
  1410.       // ----- Error log
  1411.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL"Unable to read archive '".$this->zipname."'");
  1412.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
  1413.       return(false);
  1414.     }
  1415.  
  1416.     // ----- Check the magic code
  1417.     // TBC
  1418.  
  1419.     // ----- Check the central header
  1420.     // TBC
  1421.  
  1422.     // ----- Check each file header
  1423.     // TBC
  1424.  
  1425.     // ----- Return
  1426.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1427.     return $v_result;
  1428.   }
  1429.   // --------------------------------------------------------------------------------
  1430.  
  1431.   // --------------------------------------------------------------------------------
  1432.   // Function : privParseOptions()
  1433.   // Description :
  1434.   //   This internal methods reads the variable list of arguments ($p_options_list,
  1435.   //   $p_size) and generate an array with the options and values ($v_result_list).
  1436.   //   $v_requested_options contains the options that can be present and those that
  1437.   //   must be present.
  1438.   //   $v_requested_options is an array, with the option value as key, and 'optional',
  1439.   //   or 'mandatory' as value.
  1440.   // Parameters :
  1441.   //   See above.
  1442.   // Return Values :
  1443.   //   1 on success.
  1444.   //   0 on failure.
  1445.   // --------------------------------------------------------------------------------
  1446.   function privParseOptions(&$p_options_list$p_size&$v_result_list$v_requested_options=false)
  1447.   {
  1448.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
  1449.     $v_result=1;
  1450.     
  1451.     // ----- Read the options
  1452.     $i=0;
  1453.     while ($i<$p_size{
  1454.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");
  1455.  
  1456.       // ----- Check if the option is supported
  1457.       if (!isset($v_requested_options[$p_options_list[$i]])) {
  1458.         // ----- Error log
  1459.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid optional parameter '".$p_options_list[$i]."' for this method");
  1460.  
  1461.         // ----- Return
  1462.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1463.         return PclZip::errorCode();
  1464.       }
  1465.  
  1466.       // ----- Look for next option
  1467.       switch ($p_options_list[$i]{
  1468.         // ----- Look for options that request a path value
  1469.         case PCLZIP_OPT_PATH :
  1470.         case PCLZIP_OPT_REMOVE_PATH :
  1471.         case PCLZIP_OPT_ADD_PATH :
  1472.           // ----- Check the number of parameters
  1473.           if (($i+1>= $p_size{
  1474.             // ----- Error log
  1475.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1476.  
  1477.             // ----- Return
  1478.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1479.             return PclZip::errorCode();
  1480.           }
  1481.  
  1482.           // ----- Get the value
  1483.           $v_result_list[$p_options_list[$i]] PclZipUtilTranslateWinPath($p_options_list[$i+1]false);
  1484.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1485.           $i++;
  1486.         break;
  1487.  
  1488.         case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
  1489.           // ----- Check the number of parameters
  1490.           if (($i+1>= $p_size{
  1491.             // ----- Error log
  1492.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1493.  
  1494.             // ----- Return
  1495.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1496.             return PclZip::errorCode();
  1497.           }
  1498.  
  1499.           // ----- Get the value
  1500.           if (   is_string($p_options_list[$i+1])
  1501.               && ($p_options_list[$i+1!= '')) {
  1502.             $v_result_list[$p_options_list[$i]] PclZipUtilTranslateWinPath($p_options_list[$i+1]false);
  1503.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1504.             $i++;
  1505.           }
  1506.           else {
  1507.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." set with an empty value is ignored.");
  1508.           }
  1509.         break;
  1510.  
  1511.         // ----- Look for options that request an array of string for value
  1512.         case PCLZIP_OPT_BY_NAME :
  1513.           // ----- Check the number of parameters
  1514.           if (($i+1>= $p_size{
  1515.             // ----- Error log
  1516.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1517.  
  1518.             // ----- Return
  1519.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1520.             return PclZip::errorCode();
  1521.           }
  1522.  
  1523.           // ----- Get the value
  1524.           if (is_string($p_options_list[$i+1])) {
  1525.               $v_result_list[$p_options_list[$i]][0$p_options_list[$i+1];
  1526.           }
  1527.           else if (is_array($p_options_list[$i+1])) {
  1528.               $v_result_list[$p_options_list[$i]] $p_options_list[$i+1];
  1529.           }
  1530.           else {
  1531.             // ----- Error log
  1532.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE"Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1533.  
  1534.             // ----- Return
  1535.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1536.             return PclZip::errorCode();
  1537.           }
  1538.           ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1539.           $i++;
  1540.         break;
  1541.  
  1542.         // ----- Look for options that request an EREG or PREG expression
  1543.         case PCLZIP_OPT_BY_EREG :
  1544.         case PCLZIP_OPT_BY_PREG :
  1545.         //case PCLZIP_OPT_CRYPT :
  1546.           // ----- Check the number of parameters
  1547.           if (($i+1>= $p_size{
  1548.             // ----- Error log
  1549.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1550.  
  1551.             // ----- Return
  1552.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1553.             return PclZip::errorCode();
  1554.           }
  1555.  
  1556.           // ----- Get the value
  1557.           if (is_string($p_options_list[$i+1])) {
  1558.               $v_result_list[$p_options_list[$i]] $p_options_list[$i+1];
  1559.           }
  1560.           else {
  1561.             // ----- Error log
  1562.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE"Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1563.  
  1564.             // ----- Return
  1565.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1566.             return PclZip::errorCode();
  1567.           }
  1568.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1569.           $i++;
  1570.         break;
  1571.  
  1572.         // ----- Look for options that takes a string
  1573.         case PCLZIP_OPT_COMMENT :
  1574.         case PCLZIP_OPT_ADD_COMMENT :
  1575.         case PCLZIP_OPT_PREPEND_COMMENT :
  1576.           // ----- Check the number of parameters
  1577.           if (($i+1>= $p_size{
  1578.             // ----- Error log
  1579.                                  "Missing parameter value for option '"
  1580.                                  .PclZipUtilOptionText($p_options_list[$i])
  1581.                                  ."'");
  1582.  
  1583.             // ----- Return
  1584.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1585.             return PclZip::errorCode();
  1586.           }
  1587.  
  1588.           // ----- Get the value
  1589.           if (is_string($p_options_list[$i+1])) {
  1590.               $v_result_list[$p_options_list[$i]] $p_options_list[$i+1];
  1591.           }
  1592.           else {
  1593.             // ----- Error log
  1594.                                  "Wrong parameter value for option '"
  1595.                                  .PclZipUtilOptionText($p_options_list[$i])
  1596.                                  ."'");
  1597.  
  1598.             // ----- Return
  1599.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1600.             return PclZip::errorCode();
  1601.           }
  1602.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1603.           $i++;
  1604.         break;
  1605.  
  1606.         // ----- Look for options that request an array of index
  1607.         case PCLZIP_OPT_BY_INDEX :
  1608.           // ----- Check the number of parameters
  1609.           if (($i+1>= $p_size{
  1610.             // ----- Error log
  1611.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1612.  
  1613.             // ----- Return
  1614.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1615.             return PclZip::errorCode();
  1616.           }
  1617.  
  1618.           // ----- Get the value
  1619.           $v_work_list array();
  1620.           if (is_string($p_options_list[$i+1])) {
  1621.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is a string '".$p_options_list[$i+1]."'");
  1622.  
  1623.               // ----- Remove spaces
  1624.               $p_options_list[$i+1strtr($p_options_list[$i+1]' ''');
  1625.  
  1626.               // ----- Parse items
  1627.               $v_work_list explode(","$p_options_list[$i+1]);
  1628.           }
  1629.           else if (is_integer($p_options_list[$i+1])) {
  1630.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an integer '".$p_options_list[$i+1]."'");
  1631.               $v_work_list[0$p_options_list[$i+1].'-'.$p_options_list[$i+1];
  1632.           }
  1633.           else if (is_array($p_options_list[$i+1])) {
  1634.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Index value is an array");
  1635.               $v_work_list $p_options_list[$i+1];
  1636.           }
  1637.           else {
  1638.             // ----- Error log
  1639.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE"Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1640.  
  1641.             // ----- Return
  1642.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1643.             return PclZip::errorCode();
  1644.           }
  1645.           
  1646.           // ----- Reduce the index list
  1647.           // each index item in the list must be a couple with a start and
  1648.           // an end value : [0,3], [5-5], [8-10], ...
  1649.           // ----- Check the format of each item
  1650.           $v_sort_flag=false;
  1651.           $v_sort_value=0;
  1652.           for ($j=0$j<sizeof($v_work_list)$j++{
  1653.               // ----- Explode the item
  1654.               $v_item_list explode("-"$v_work_list[$j]);
  1655.               $v_size_item_list sizeof($v_item_list);
  1656.               
  1657.               // ----- TBC : Here we might check that each item is a
  1658.               // real integer ...
  1659.               
  1660.               // ----- Look for single value
  1661.               if ($v_size_item_list == 1{
  1662.                   // ----- Set the option value
  1663.                   $v_result_list[$p_options_list[$i]][$j]['start'$v_item_list[0];
  1664.                   $v_result_list[$p_options_list[$i]][$j]['end'$v_item_list[0];
  1665.               }
  1666.               elseif ($v_size_item_list == 2{
  1667.                   // ----- Set the option value
  1668.                   $v_result_list[$p_options_list[$i]][$j]['start'$v_item_list[0];
  1669.                   $v_result_list[$p_options_list[$i]][$j]['end'$v_item_list[1];
  1670.               }
  1671.               else {
  1672.                   // ----- Error log
  1673.                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE"Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1674.  
  1675.                   // ----- Return
  1676.                   //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1677.                   return PclZip::errorCode();
  1678.               }
  1679.  
  1680.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extracted index item = [".$v_result_list[$p_options_list[$i]][$j]['start'].",".$v_result_list[$p_options_list[$i]][$j]['end']."]");
  1681.  
  1682.               // ----- Look for list sort
  1683.               if ($v_result_list[$p_options_list[$i]][$j]['start'$v_sort_value{
  1684.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The list should be sorted ...");
  1685.                   $v_sort_flag=true;
  1686.  
  1687.                   // ----- TBC : An automatic sort should be writen ...
  1688.                   // ----- Error log
  1689.                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE"Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1690.  
  1691.                   // ----- Return
  1692.                   //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1693.                   return PclZip::errorCode();
  1694.               }
  1695.               $v_sort_value $v_result_list[$p_options_list[$i]][$j]['start'];
  1696.           }
  1697.           
  1698.           // ----- Sort the items
  1699.           if ($v_sort_flag{
  1700.               // TBC : To Be Completed
  1701.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "List sorting is not yet write ...");
  1702.           }
  1703.  
  1704.           // ----- Next option
  1705.           $i++;
  1706.         break;
  1707.  
  1708.         // ----- Look for options that request no value
  1709.         case PCLZIP_OPT_REMOVE_ALL_PATH :
  1710.         case PCLZIP_OPT_EXTRACT_AS_STRING :
  1711.         case PCLZIP_OPT_NO_COMPRESSION :
  1712.         case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
  1713.         case PCLZIP_OPT_REPLACE_NEWER :
  1714.         case PCLZIP_OPT_STOP_ON_ERROR :
  1715.           $v_result_list[$p_options_list[$i]] true;
  1716.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1717.         break;
  1718.  
  1719.         // ----- Look for options that request an octal value
  1720.         case PCLZIP_OPT_SET_CHMOD :
  1721.           // ----- Check the number of parameters
  1722.           if (($i+1>= $p_size{
  1723.             // ----- Error log
  1724.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1725.  
  1726.             // ----- Return
  1727.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1728.             return PclZip::errorCode();
  1729.           }
  1730.  
  1731.           // ----- Get the value
  1732.           $v_result_list[$p_options_list[$i]] $p_options_list[$i+1];
  1733.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1734.           $i++;
  1735.         break;
  1736.  
  1737.         // ----- Look for options that request a call-back
  1738.         case PCLZIP_CB_PRE_EXTRACT :
  1739.         case PCLZIP_CB_POST_EXTRACT :
  1740.         case PCLZIP_CB_PRE_ADD :
  1741.         case PCLZIP_CB_POST_ADD :
  1742.         /* for futur use
  1743.         case PCLZIP_CB_PRE_DELETE :
  1744.         case PCLZIP_CB_POST_DELETE :
  1745.         case PCLZIP_CB_PRE_LIST :
  1746.         case PCLZIP_CB_POST_LIST :
  1747.         */
  1748.           // ----- Check the number of parameters
  1749.           if (($i+1>= $p_size{
  1750.             // ----- Error log
  1751.             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE"Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1752.  
  1753.             // ----- Return
  1754.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1755.             return PclZip::errorCode();
  1756.           }
  1757.  
  1758.           // ----- Get the value
  1759.           $v_function_name $p_options_list[$i+1];
  1760.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "call-back ".PclZipUtilOptionText($p_options_list[$i])." = '".$v_function_name."'");
  1761.  
  1762.           // ----- Check that the value is a valid existing function
  1763.           if (!function_exists($v_function_name)) {
  1764.             // ----- Error log
  1765.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE"Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1766.  
  1767.             // ----- Return
  1768.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1769.             return PclZip::errorCode();
  1770.           }
  1771.  
  1772.           // ----- Set the attribute
  1773.           $v_result_list[$p_options_list[$i]] $v_function_name;
  1774.           $i++;
  1775.         break;
  1776.  
  1777.         default :
  1778.           // ----- Error log
  1779.                                "Unknown parameter '"
  1780.                                .$p_options_list[$i]."'");
  1781.  
  1782.           // ----- Return
  1783.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1784.           return PclZip::errorCode();
  1785.       }
  1786.  
  1787.       // ----- Next options
  1788.       $i++;
  1789.     }
  1790.  
  1791.     // ----- Look for mandatory options
  1792.     if ($v_requested_options !== false{
  1793.       for ($key=reset($v_requested_options)$key=key($v_requested_options)$key=next($v_requested_options)) {
  1794.         // ----- Look for mandatory option
  1795.         if ($v_requested_options[$key== 'mandatory'{
  1796.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
  1797.           // ----- Look if present
  1798.           if (!isset($v_result_list[$key])) {
  1799.             // ----- Error log
  1800.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
  1801.  
  1802.             // ----- Return
  1803.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1804.             return PclZip::errorCode();
  1805.           }
  1806.         }
  1807.       }
  1808.     }
  1809.  
  1810.     // ----- Return
  1811.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1812.     return $v_result;
  1813.   }
  1814.   // --------------------------------------------------------------------------------
  1815.  
  1816.   // --------------------------------------------------------------------------------
  1817.   // Function : privFileDescrParseAtt()
  1818.   // Description :
  1819.   // Parameters :
  1820.   // Return Values :
  1821.   //   1 on success.
  1822.   //   0 on failure.
  1823.   // --------------------------------------------------------------------------------
  1824.   function privFileDescrParseAtt(&$p_file_list&$p_filedescr$v_options$v_requested_options=false)
  1825.   {
  1826.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrParseAtt", "");
  1827.     $v_result=1;
  1828.     
  1829.     // ----- For each file in the list check the attributes
  1830.     foreach ($p_file_list as $v_key => $v_value{
  1831.     
  1832.       // ----- Check if the option is supported
  1833.       if (!isset($v_requested_options[$v_key])) {
  1834.         // ----- Error log
  1835.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid file attribute '".$v_key."' for this file");
  1836.  
  1837.         // ----- Return
  1838.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1839.         return PclZip::errorCode();
  1840.       }
  1841.  
  1842.       // ----- Look for attribute
  1843.       switch ($v_key{
  1844.         case PCLZIP_ATT_FILE_NAME :
  1845.           if (!is_string($v_value)) {
  1846.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE"Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1847.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1848.             return PclZip::errorCode();
  1849.           }
  1850.  
  1851.           $p_filedescr['filename'PclZipUtilPathReduction($v_value);
  1852.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
  1853.           
  1854.           if ($p_filedescr['filename'== ''{
  1855.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE"Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1856.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1857.             return PclZip::errorCode();
  1858.           }
  1859.  
  1860.         break;
  1861.  
  1862.         case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
  1863.           if (!is_string($v_value)) {
  1864.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE"Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1865.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1866.             return PclZip::errorCode();
  1867.           }
  1868.  
  1869.           $p_filedescr['new_short_name'PclZipUtilPathReduction($v_value);
  1870.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
  1871.  
  1872.           if ($p_filedescr['new_short_name'== ''{
  1873.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE"Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1874.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1875.             return PclZip::errorCode();
  1876.           }
  1877.         break;
  1878.  
  1879.         case PCLZIP_ATT_FILE_NEW_FULL_NAME :
  1880.           if (!is_string($v_value)) {
  1881.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE"Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1882.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1883.             return PclZip::errorCode();
  1884.           }
  1885.  
  1886.           $p_filedescr['new_full_name'PclZipUtilPathReduction($v_value);
  1887.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($v_key)." = '".$v_value."'");
  1888.  
  1889.           if ($p_filedescr['new_full_name'== ''{
  1890.             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE"Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1891.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1892.             return PclZip::errorCode();
  1893.           }
  1894.         break;
  1895.  
  1896.         default :
  1897.           // ----- Error log
  1898.                                    "Unknown parameter '".$v_key."'");
  1899.  
  1900.           // ----- Return
  1901.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1902.           return PclZip::errorCode();
  1903.       }
  1904.  
  1905.       // ----- Look for mandatory options
  1906.       if ($v_requested_options !== false{
  1907.         for ($key=reset($v_requested_options)$key=key($v_requested_options)$key=next($v_requested_options)) {
  1908.           // ----- Look for mandatory option
  1909.           if ($v_requested_options[$key== 'mandatory'{
  1910.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Detect a mandatory option : ".PclZipUtilOptionText($key)."(".$key.")");
  1911.             // ----- Look if present
  1912.             if (!isset($p_file_list[$key])) {
  1913.               PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
  1914.               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1915.               return PclZip::errorCode();
  1916.             }
  1917.           }
  1918.         }
  1919.       }
  1920.     
  1921.     // end foreach
  1922.     }
  1923.     
  1924.     // ----- Return
  1925.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1926.     return $v_result;
  1927.   }
  1928.   // --------------------------------------------------------------------------------
  1929.  
  1930.   // --------------------------------------------------------------------------------
  1931.   // Function : privFileDescrExpand()
  1932.   // Description :
  1933.   // Parameters :
  1934.   // Return Values :
  1935.   //   1 on success.
  1936.   //   0 on failure.
  1937.   // --------------------------------------------------------------------------------
  1938.   function privFileDescrExpand(&$p_filedescr_list&$p_options)
  1939.   {
  1940.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privFileDescrExpand", "");
  1941.     $v_result=1;
  1942.     
  1943.     // ----- Create a result list
  1944.     $v_result_list array();
  1945.     
  1946.     // ----- Look each entry
  1947.     for ($i=0$i<sizeof($p_filedescr_list)$i++{
  1948.       // ----- Get filedescr
  1949.       $v_descr $p_filedescr_list[$i];
  1950.       
  1951.       // ----- Reduce the filename
  1952.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr before reduction :'".$v_descr['filename']."'");
  1953.       $v_descr['filename'PclZipUtilTranslateWinPath($v_descr['filename']false);
  1954.       $v_descr['filename'PclZipUtilPathReduction($v_descr['filename']);
  1955.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filedescr after reduction :'".$v_descr['filename']."'");
  1956.       
  1957.       // ----- Get type of descr
  1958.       if (!file_exists($v_descr['filename'])) {
  1959.         // ----- Error log
  1960.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_descr['filename']."' does not exists");
  1961.         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE"File '".$v_descr['filename']."' does not exists");
  1962.  
  1963.         // ----- Return
  1964.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1965.         return PclZip::errorCode();
  1966.       }
  1967.       if (@is_file($v_descr['filename'])) {
  1968.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a file");
  1969.         $v_descr['type''file';
  1970.       }
  1971.       else if (@is_dir($v_descr['filename'])) {
  1972.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "This is a folder");
  1973.         $v_descr['type''folder';
  1974.       }
  1975.       else if (@is_link($v_descr['filename'])) {
  1976.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : link");
  1977.         // skip
  1978.         continue;
  1979.       }
  1980.       else {
  1981.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Unsupported file type : unknown type");
  1982.         // skip
  1983.         continue;
  1984.       }
  1985.       
  1986.       // ----- Calculate the stored filename
  1987.       $this->privCalculateStoredFilename($v_descr$p_options);
  1988.       
  1989.       // ----- Add the descriptor in result list
  1990.       $v_result_list[sizeof($v_result_list)$v_descr;
  1991.       
  1992.       // ----- Look for folder
  1993.       if ($v_descr['type'== 'folder'{
  1994.         // ----- List of items in folder
  1995.         $v_dirlist_descr array();
  1996.         $v_dirlist_nb 0;
  1997.         if ($v_folder_handler @opendir($v_descr['filename'])) {
  1998.           while (($v_item_handler @readdir($v_folder_handler)) !== false{
  1999.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for '".$v_item_handler."' in the directory");
  2000.  
  2001.             // ----- Skip '.' and '..'
  2002.             if (($v_item_handler == '.'|| ($v_item_handler == '..')) {
  2003.                 continue;
  2004.             }
  2005.             
  2006.             // ----- Compose the full filename
  2007.             $v_dirlist_descr[$v_dirlist_nb]['filename'$v_descr['filename'].'/'.$v_item_handler;
  2008.             
  2009.             // ----- Look for different stored filename
  2010.             // Because the name of the folder was changed, the name of the
  2011.             // files/sub-folders also change
  2012.             if ($v_descr['stored_filename'!= $v_descr['filename']{
  2013.               $v_dirlist_descr[$v_dirlist_nb]['new_full_name'$v_descr['stored_filename'].'/'.$v_item_handler;
  2014.             }
  2015.       
  2016.             $v_dirlist_nb++;
  2017.           }
  2018.         }
  2019.         else {
  2020.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to open dir '".$v_descr['filename']."' in read mode. Skipped.");
  2021.           // TBC : unable to open folder in read mode
  2022.         }
  2023.         
  2024.         // ----- Expand each element of the list
  2025.         if ($v_dirlist_nb != 0{
  2026.           // ----- Expand
  2027.           if (($v_result $this->privFileDescrExpand($v_dirlist_descr$p_options)) != 1{
  2028.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2029.             return $v_result;
  2030.           }
  2031.           
  2032.           // ----- Concat the resulting list
  2033.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Merging result list (size '".sizeof($v_result_list)."') with dirlist (size '".sizeof($v_dirlist_descr)."')");
  2034.           $v_result_list array_merge($v_result_list$v_dirlist_descr);
  2035.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "merged result list is size '".sizeof($v_result_list)."'");
  2036.         }
  2037.         else {
  2038.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Nothing in this folder to expand.");
  2039.         }
  2040.           
  2041.         // ----- Free local array
  2042.         unset($v_dirlist_descr);
  2043.       }
  2044.     }
  2045.     
  2046.     // ----- Get the result list
  2047.     $p_filedescr_list $v_result_list;
  2048.  
  2049.     // ----- Return
  2050.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2051.     return $v_result;
  2052.   }
  2053.   // --------------------------------------------------------------------------------
  2054.  
  2055.   // --------------------------------------------------------------------------------
  2056.   // Function : privCreate()
  2057.   // Description :
  2058.   // Parameters :
  2059.   // Return Values :
  2060.   // --------------------------------------------------------------------------------
  2061.   function privCreate($p_filedescr_list&$p_result_list&$p_options)
  2062.   {
  2063.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCreate", "list");
  2064.     $v_result=1;
  2065.     $v_list_detail array();
  2066.     
  2067.     // ----- Magic quotes trick
  2068.     $this->privDisableMagicQuotes();
  2069.  
  2070.     // ----- Open the file in write mode
  2071.     if (($v_result $this->privOpenFd('wb')) != 1)
  2072.     {
  2073.       // ----- Return
  2074.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2075.       return $v_result;
  2076.     }
  2077.  
  2078.     // ----- Add the list of files
  2079.     $v_result $this->privAddList($p_filedescr_list$p_result_list$p_options);
  2080.  
  2081.     // ----- Close
  2082.     $this->privCloseFd();
  2083.  
  2084.     // ----- Magic quotes trick
  2085.     $this->privSwapBackMagicQuotes();
  2086.  
  2087.     // ----- Return
  2088.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2089.     return $v_result;
  2090.   }
  2091.   // --------------------------------------------------------------------------------
  2092.  
  2093.   // --------------------------------------------------------------------------------
  2094.   // Function : privAdd()
  2095.   // Description :
  2096.   // Parameters :
  2097.   // Return Values :
  2098.   // --------------------------------------------------------------------------------
  2099.   function privAdd($p_filedescr_list&$p_result_list&$p_options)
  2100.   {
  2101.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAdd", "list");
  2102.     $v_result=1;
  2103.     $v_list_detail array();
  2104.  
  2105.     // ----- Look if the archive exists or is empty
  2106.     if ((!is_file($this->zipname)) || (filesize($this->zipname== 0))
  2107.     {
  2108.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, or is empty, create it.");
  2109.  
  2110.       // ----- Do a create
  2111.       $v_result $this->privCreate($p_filedescr_list$p_result_list$p_options);
  2112.  
  2113.       // ----- Return
  2114.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2115.       return $v_result;
  2116.     }
  2117.     // ----- Magic quotes trick
  2118.     $this->privDisableMagicQuotes();
  2119.  
  2120.     // ----- Open the zip file
  2121.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  2122.     if (($v_result=$this->privOpenFd('rb')) != 1)
  2123.     {
  2124.       // ----- Magic quotes trick
  2125.       $this->privSwapBackMagicQuotes();
  2126.  
  2127.       // ----- Return
  2128.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2129.       return $v_result;
  2130.     }
  2131.  
  2132.     // ----- Read the central directory informations
  2133.     $v_central_dir array();
  2134.     if (($v_result $this->privReadEndCentralDir($v_central_dir)) != 1)
  2135.     {
  2136.       $this->privCloseFd();
  2137.       $this->privSwapBackMagicQuotes();
  2138.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2139.       return $v_result;
  2140.     }
  2141.  
  2142.     // ----- Go to beginning of File
  2143.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
  2144.     @rewind($this->zip_fd);
  2145.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
  2146.  
  2147.     // ----- Creates a temporay file
  2148.     $v_zip_temp_name PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  2149.  
  2150.     // ----- Open the temporary file in write mode
  2151.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  2152.     if (($v_zip_temp_fd @fopen($v_zip_temp_name'wb')) == 0)
  2153.     {
  2154.       $this->privCloseFd();
  2155.       $this->privSwapBackMagicQuotes();
  2156.  
  2157.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
  2158.  
  2159.       // ----- Return
  2160.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2161.       return PclZip::errorCode();
  2162.     }
  2163.  
  2164.     // ----- Copy the files from the archive to the temporary file
  2165.     // TBC : Here I should better append the file and go back to erase the central dir
  2166.     $v_size $v_central_dir['offset'];
  2167.     while ($v_size != 0)
  2168.     {
  2169.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  2170.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  2171.       $v_buffer fread($this->zip_fd$v_read_size);
  2172.       @fwrite($v_zip_temp_fd$v_buffer$v_read_size);
  2173.       $v_size -= $v_read_size;
  2174.     }
  2175.  
  2176.     // ----- Swap the file descriptor
  2177.     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
  2178.     // the following methods on the temporary fil and not the real archive
  2179.     $v_swap $this->zip_fd;
  2180.     $this->zip_fd = $v_zip_temp_fd;
  2181.     $v_zip_temp_fd $v_swap;
  2182.  
  2183.     // ----- Add the files
  2184.     $v_header_list array();
  2185.     if (($v_result $this->privAddFileList($p_filedescr_list$v_header_list$p_options)) != 1)
  2186.     {
  2187.       fclose($v_zip_temp_fd);
  2188.       $this->privCloseFd();
  2189.       @unlink($v_zip_temp_name);
  2190.       $this->privSwapBackMagicQuotes();
  2191.  
  2192.       // ----- Return
  2193.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2194.       return $v_result;
  2195.     }
  2196.  
  2197.     // ----- Store the offset of the central dir
  2198.     $v_offset @ftell($this->zip_fd);
  2199.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
  2200.  
  2201.     // ----- Copy the block of file headers from the old archive
  2202.     $v_size $v_central_dir['size'];
  2203.     while ($v_size != 0)
  2204.     {
  2205.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  2206.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  2207.       $v_buffer @fread($v_zip_temp_fd$v_read_size);
  2208.       @fwrite($this->zip_fd$v_buffer$v_read_size);
  2209.       $v_size -= $v_read_size;
  2210.     }
  2211.  
  2212.     // ----- Create the Central Dir files header
  2213.     for ($i=0$v_count=0$i<sizeof($v_header_list)$i++)
  2214.     {
  2215.       // ----- Create the file header
  2216.       if ($v_header_list[$i]['status'== 'ok'{
  2217.         if (($v_result $this->privWriteCentralFileHeader($v_header_list[$i])) != 1{
  2218.           fclose($v_zip_temp_fd);
  2219.           $this->privCloseFd();
  2220.           @unlink($v_zip_temp_name);
  2221.           $this->privSwapBackMagicQuotes();
  2222.  
  2223.           // ----- Return
  2224.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2225.           return $v_result;
  2226.         }
  2227.         $v_count++;
  2228.       }
  2229.  
  2230.       // ----- Transform the header to a 'usable' info
  2231.       $this->privConvertHeader2FileInfo($v_header_list[$i]$p_result_list[$i]);
  2232.     }
  2233.  
  2234.     // ----- Zip file comment
  2235.     $v_comment $v_central_dir['comment'];
  2236.     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  2237.       $v_comment $p_options[PCLZIP_OPT_COMMENT];
  2238.     }
  2239.     if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
  2240.       $v_comment $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
  2241.     }
  2242.     if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
  2243.       $v_comment $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
  2244.     }
  2245.  
  2246.     // ----- Calculate the size of the central header
  2247.     $v_size @ftell($this->zip_fd)-$v_offset;
  2248.  
  2249.     // ----- Create the central dir footer
  2250.     if (($v_result $this->privWriteCentralHeader($v_count+$v_central_dir['entries']$v_size$v_offset$v_comment)) != 1)
  2251.     {
  2252.       // ----- Reset the file list
  2253.       unset($v_header_list);
  2254.       $this->privSwapBackMagicQuotes();
  2255.  
  2256.       // ----- Return
  2257.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2258.       return $v_result;
  2259.     }
  2260.  
  2261.     // ----- Swap back the file descriptor
  2262.     $v_swap $this->zip_fd;
  2263.     $this->zip_fd = $v_zip_temp_fd;
  2264.     $v_zip_temp_fd $v_swap;
  2265.  
  2266.     // ----- Close
  2267.     $this->privCloseFd();
  2268.  
  2269.     // ----- Close the temporary file
  2270.     @fclose($v_zip_temp_fd);
  2271.  
  2272.     // ----- Magic quotes trick
  2273.     $this->privSwapBackMagicQuotes();
  2274.  
  2275.     // ----- Delete the zip file
  2276.     // TBC : I should test the result ...
  2277.     @unlink($this->zipname);
  2278.  
  2279.     // ----- Rename the temporary file
  2280.     // TBC : I should test the result ...
  2281.     //@rename($v_zip_temp_name, $this->zipname);
  2282.     PclZipUtilRename($v_zip_temp_name$this->zipname);
  2283.  
  2284.     // ----- Return
  2285.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2286.     return $v_result;
  2287.   }
  2288.   // --------------------------------------------------------------------------------
  2289.  
  2290.   // --------------------------------------------------------------------------------
  2291.   // Function : privOpenFd()
  2292.   // Description :
  2293.   // Parameters :
  2294.   // --------------------------------------------------------------------------------
  2295.   function privOpenFd($p_mode)
  2296.   {
  2297.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privOpenFd", 'mode='.$p_mode);
  2298.     $v_result=1;
  2299.  
  2300.     // ----- Look if already open
  2301.     if ($this->zip_fd != 0)
  2302.     {
  2303.       // ----- Error log
  2304.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Zip file \''.$this->zipname.'\' already open');
  2305.  
  2306.       // ----- Return
  2307.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2308.       return PclZip::errorCode();
  2309.     }
  2310.  
  2311.     // ----- Open the zip file
  2312.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Open file in '.$p_mode.' mode');
  2313.     if (($this->zip_fd = @fopen($this->zipname$p_mode)) == 0)
  2314.     {
  2315.       // ----- Error log
  2316.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
  2317.  
  2318.       // ----- Return
  2319.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2320.       return PclZip::errorCode();
  2321.     }
  2322.  
  2323.     // ----- Return
  2324.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2325.     return $v_result;
  2326.   }
  2327.   // --------------------------------------------------------------------------------
  2328.  
  2329.   // --------------------------------------------------------------------------------
  2330.   // Function : privCloseFd()
  2331.   // Description :
  2332.   // Parameters :
  2333.   // --------------------------------------------------------------------------------
  2334.   function privCloseFd()
  2335.   {
  2336.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCloseFd", "");
  2337.     $v_result=1;
  2338.  
  2339.     if ($this->zip_fd != 0)
  2340.       @fclose($this->zip_fd);
  2341.     $this->zip_fd = 0;
  2342.  
  2343.     // ----- Return
  2344.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2345.     return $v_result;
  2346.   }
  2347.   // --------------------------------------------------------------------------------
  2348.  
  2349.   // --------------------------------------------------------------------------------
  2350.   // Function : privAddList()
  2351.   // Description :
  2352.   //   $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
  2353.   //   different from the real path of the file. This is usefull if you want to have PclTar
  2354.   //   running in any directory, and memorize relative path from an other directory.
  2355.   // Parameters :
  2356.   //   $p_list : An array containing the file or directory names to add in the tar
  2357.   //   $p_result_list : list of added files with their properties (specially the status field)
  2358.   //   $p_add_dir : Path to add in the filename path archived
  2359.   //   $p_remove_dir : Path to remove in the filename path archived
  2360.   // Return Values :
  2361.   // --------------------------------------------------------------------------------
  2362. //  function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
  2363.   function privAddList($p_filedescr_list&$p_result_list&$p_options)
  2364.   {
  2365.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddList", "list");
  2366.     $v_result=1;
  2367.  
  2368.     // ----- Add the files
  2369.     $v_header_list array();
  2370.     if (($v_result $this->privAddFileList($p_filedescr_list$v_header_list$p_options)) != 1)
  2371.     {
  2372.       // ----- Return
  2373.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2374.       return $v_result;
  2375.     }
  2376.  
  2377.     // ----- Store the offset of the central dir
  2378.     $v_offset @ftell($this->zip_fd);
  2379.  
  2380.     // ----- Create the Central Dir files header
  2381.     for ($i=0,$v_count=0$i<sizeof($v_header_list)$i++)
  2382.     {
  2383.       // ----- Create the file header
  2384.       if ($v_header_list[$i]['status'== 'ok'{
  2385.         if (($v_result $this->privWriteCentralFileHeader($v_header_list[$i])) != 1{
  2386.           // ----- Return
  2387.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2388.           return $v_result;
  2389.         }
  2390.         $v_count++;
  2391.       }
  2392.  
  2393.       // ----- Transform the header to a 'usable' info
  2394.       $this->privConvertHeader2FileInfo($v_header_list[$i]$p_result_list[$i]);
  2395.     }
  2396.  
  2397.     // ----- Zip file comment
  2398.     $v_comment '';
  2399.     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  2400.       $v_comment $p_options[PCLZIP_OPT_COMMENT];
  2401.     }
  2402.  
  2403.     // ----- Calculate the size of the central header
  2404.     $v_size @ftell($this->zip_fd)-$v_offset;
  2405.  
  2406.     // ----- Create the central dir footer
  2407.     if (($v_result $this->privWriteCentralHeader($v_count$v_size$v_offset$v_comment)) != 1)
  2408.     {
  2409.       // ----- Reset the file list
  2410.       unset($v_header_list);
  2411.  
  2412.       // ----- Return
  2413.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2414.       return $v_result;
  2415.     }
  2416.  
  2417.     // ----- Return
  2418.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2419.     return $v_result;
  2420.   }
  2421.   // --------------------------------------------------------------------------------
  2422.  
  2423.   // --------------------------------------------------------------------------------
  2424.   // Function : privAddFileList()
  2425.   // Description :
  2426.   // Parameters :
  2427.   //   $p_filedescr_list : An array containing the file description 
  2428.   //                      or directory names to add in the zip
  2429.   //   $p_result_list : list of added files with their properties (specially the status field)
  2430.   // Return Values :
  2431.   // --------------------------------------------------------------------------------
  2432.   function privAddFileList($p_filedescr_list&$p_result_list&$p_options)
  2433.   {
  2434.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFileList", "filedescr_list");
  2435.     $v_result=1;
  2436.     $v_header array();
  2437.  
  2438.     // ----- Recuperate the current number of elt in list
  2439.     $v_nb sizeof($p_result_list);
  2440.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Before add, list have ".$v_nb." elements");
  2441.  
  2442.     // ----- Loop on the files
  2443.     for ($j=0($j<sizeof($p_filedescr_list)) && ($v_result==1)$j++{
  2444.       // ----- Format the filename
  2445.       $p_filedescr_list[$j]['filename']
  2446.       = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename']false);
  2447.       
  2448.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Looking for file '".$p_filedescr_list[$j]['filename']."'");
  2449.  
  2450.       // ----- Skip empty file names
  2451.       // TBC : Can this be possible ? not checked in DescrParseAtt ?
  2452.       if ($p_filedescr_list[$j]['filename'== ""{
  2453.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");
  2454.         continue;
  2455.       }
  2456.  
  2457.       // ----- Check the filename
  2458.       if (!file_exists($p_filedescr_list[$j]['filename'])) {
  2459.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_filedescr_list[$j]['filename']."' does not exists");
  2460.         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE"File '".$p_filedescr_list[$j]['filename']."' does not exists");
  2461.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2462.         return PclZip::errorCode();
  2463.       }
  2464.  
  2465.       // ----- Look if it is a file or a dir with no all path remove option
  2466.       if (   (is_file($p_filedescr_list[$j]['filename']))
  2467.           || (   is_dir($p_filedescr_list[$j]['filename'])
  2468.               && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
  2469.                   || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
  2470.  
  2471.         // ----- Add the file
  2472.         $v_result $this->privAddFile($p_filedescr_list[$j]$v_header,
  2473.                                        $p_options);
  2474.         if ($v_result != 1{
  2475.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2476.           return $v_result;
  2477.         }
  2478.  
  2479.         // ----- Store the file infos
  2480.         $p_result_list[$v_nb++$v_header;
  2481.       }
  2482.     }
  2483.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "After add, list have ".$v_nb." elements");
  2484.  
  2485.     // ----- Return
  2486.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2487.     return $v_result;
  2488.   }
  2489.   // --------------------------------------------------------------------------------
  2490.  
  2491.   // --------------------------------------------------------------------------------
  2492.   // Function : privAddFile()
  2493.   // Description :
  2494.   // Parameters :
  2495.   // Return Values :
  2496.   // --------------------------------------------------------------------------------
  2497.   function privAddFile($p_filedescr&$p_header&$p_options)
  2498.   {
  2499.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privAddFile", "filename='".$p_filedescr['filename']."'");
  2500.     $v_result=1;
  2501.     
  2502.     // ----- Working variable
  2503.     $p_filename $p_filedescr['filename'];
  2504.  
  2505.     // TBC : Already done in the fileAtt check ... ?
  2506.     if ($p_filename == ""{
  2507.       // ----- Error log
  2508.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER"Invalid file list parameter (invalid or empty list)");
  2509.  
  2510.       // ----- Return
  2511.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2512.       return PclZip::errorCode();
  2513.     }
  2514.   
  2515.     // ----- Look for a stored different filename 
  2516.     if (isset($p_filedescr['stored_filename'])) {
  2517.       $v_stored_filename $p_filedescr['stored_filename'];
  2518.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is NOT the same "'.$v_stored_filename.'"');
  2519.     }
  2520.     else {
  2521.       $v_stored_filename $p_filedescr['stored_filename'];
  2522.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'Stored filename is the same');
  2523.     }
  2524.  
  2525.     // ----- Set the file properties
  2526.     clearstatcache();
  2527.     $p_header['version'20;
  2528.     $p_header['version_extracted'10;
  2529.     $p_header['flag'0;
  2530.     $p_header['compression'0;
  2531.     $p_header['mtime'filemtime($p_filename);
  2532.     $p_header['crc'0;
  2533.     $p_header['compressed_size'0;
  2534.     $p_header['size'filesize($p_filename);
  2535.     $p_header['filename_len'strlen($p_filename);
  2536.     $p_header['extra_len'0;
  2537.     $p_header['comment_len'0;
  2538.     $p_header['disk'0;
  2539.     $p_header['internal'0;
  2540. //    $p_header['external'] = (is_file($p_filename)?0xFE49FFE0:0x41FF0010);
  2541.     $p_header['external'(is_file($p_filename)?0x00000000:0x00000010);
  2542.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header external extension '".sprintf("0x%X",$p_header['external'])."'");
  2543.     $p_header['offset'0;
  2544.     $p_header['filename'$p_filename;
  2545.     $p_header['stored_filename'$v_stored_filename;
  2546.     $p_header['extra''';
  2547.     $p_header['comment''';
  2548.     $p_header['status''ok';
  2549.     $p_header['index'= -1;
  2550.  
  2551.     // ----- Look for pre-add callback
  2552.     if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
  2553.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_ADD]."()') is defined for the extraction");
  2554.  
  2555.       // ----- Generate a local information
  2556.       $v_local_header array();
  2557.       $this->privConvertHeader2FileInfo($p_header$v_local_header);
  2558.  
  2559.       // ----- Call the callback
  2560.       // Here I do not use call_user_func() because I need to send a reference to the
  2561.       // header.
  2562.       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
  2563.       if ($v_result == 0{
  2564.         // ----- Change the file status
  2565.         $p_header['status'"skipped";
  2566.         $v_result 1;
  2567.       }
  2568.  
  2569.       // ----- Update the informations
  2570.       // Only some fields can be modified
  2571.       if ($p_header['stored_filename'!= $v_local_header['stored_filename']{
  2572.         $p_header['stored_filename'PclZipUtilPathReduction($v_local_header['stored_filename']);
  2573.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New stored filename is '".$p_header['stored_filename']."'");
  2574.       }
  2575.     }
  2576.  
  2577.     // ----- Look for empty stored filename
  2578.     if ($p_header['stored_filename'== ""{
  2579.       $p_header['status'"filtered";
  2580.     }
  2581.     
  2582.     // ----- Check the path length
  2583.     if (strlen($p_header['stored_filename']0xFF{
  2584.       $p_header['status''filename_too_long';
  2585.     }
  2586.  
  2587.     // ----- Look if no error, or file not skipped
  2588.     if ($p_header['status'== 'ok'{
  2589.  
  2590.       // ----- Look for a file
  2591.       if (is_file($p_filename))
  2592.       {
  2593.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a file");
  2594.         // ----- Open the source file
  2595.         if (($v_file @fopen($p_filename"rb")) == 0{
  2596.           PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL"Unable to open file '$p_filename' in binary read mode");
  2597.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2598.           return PclZip::errorCode();
  2599.         }
  2600.  
  2601.         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]{
  2602.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be compressed");
  2603.           // ----- Read the file content
  2604.           $v_content_compressed @fread($v_file$p_header['size']);
  2605.  
  2606.           // ----- Calculate the CRC
  2607.           $p_header['crc'@crc32($v_content_compressed);
  2608.  
  2609.           // ----- Set header parameters
  2610.           $p_header['compressed_size'$p_header['size'];
  2611.           $p_header['compression'0;
  2612.         }
  2613.         else {
  2614.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will be compressed");
  2615.           // ----- Read the file content
  2616.           $v_content @fread($v_file$p_header['size']);
  2617.  
  2618.           // ----- Calculate the CRC
  2619.           $p_header['crc'@crc32($v_content);
  2620.  
  2621.           // ----- Compress the file
  2622.           $v_content_compressed @gzdeflate($v_content);
  2623.  
  2624.           // ----- Set header parameters
  2625.           $p_header['compressed_size'strlen($v_content_compressed);
  2626.           $p_header['compression'8;
  2627.         }
  2628.         
  2629.         // ----- Look for encryption
  2630.         /*
  2631.         if ((isset($p_options[PCLZIP_OPT_CRYPT]))
  2632.             && ($p_options[PCLZIP_OPT_CRYPT] != "")) {
  2633.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File need to be crypted ....");
  2634.           
  2635.           // Should be a random header
  2636.           $v_header = 'xxxxxxxxxxxx';
  2637.           $v_content_compressed = PclZipUtilZipEncrypt($v_content_compressed,
  2638.                                                    $p_header['compressed_size'],
  2639.                                                    $v_header,
  2640.                                                    $p_header['crc'],
  2641.                                                    "test");
  2642.                                                    
  2643.           $p_header['compressed_size'] += 12;
  2644.           $p_header['flag'] = 1;
  2645.           
  2646.           // ----- Add the header to the data
  2647.           $v_content_compressed = $v_header.$v_content_compressed;
  2648.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size after header : ".strlen($v_content_compressed)."");
  2649.         }
  2650.         */
  2651.  
  2652.         // ----- Call the header generation
  2653.         if (($v_result $this->privWriteFileHeader($p_header)) != 1{
  2654.           @fclose($v_file);
  2655.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2656.           return $v_result;
  2657.         }
  2658.  
  2659.         // ----- Write the compressed (or not) content
  2660.         @fwrite($this->zip_fd
  2661.                     $v_content_compressed$p_header['compressed_size']);
  2662.         
  2663.         // ----- Close the file
  2664.         @fclose($v_file);
  2665.       }
  2666.  
  2667.       // ----- Look for a directory
  2668.       else {
  2669.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "'".$p_filename."' is a folder");
  2670.         // ----- Look for directory last '/'
  2671.         if (@substr($p_header['stored_filename']-1!= '/'{
  2672.           $p_header['stored_filename'.= '/';
  2673.         }
  2674.  
  2675.         // ----- Set the file properties
  2676.         $p_header['size'0;
  2677.         //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked
  2678.         $p_header['external'0x00000010;   // Value for a folder : to be checked
  2679.  
  2680.         // ----- Call the header generation
  2681.         if (($v_result $this->privWriteFileHeader($p_header)) != 1)
  2682.         {
  2683.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2684.           return $v_result;
  2685.         }
  2686.       }
  2687.     }
  2688.  
  2689.     // ----- Look for post-add callback
  2690.     if (isset($p_options[PCLZIP_CB_POST_ADD])) {
  2691.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_ADD]."()') is defined for the extraction");
  2692.  
  2693.       // ----- Generate a local information
  2694.       $v_local_header array();
  2695.       $this->privConvertHeader2FileInfo($p_header$v_local_header);
  2696.  
  2697.       // ----- Call the callback
  2698.       // Here I do not use call_user_func() because I need to send a reference to the
  2699.       // header.
  2700.       eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
  2701.       if ($v_result == 0{
  2702.         // ----- Ignored
  2703.         $v_result 1;
  2704.       }
  2705.  
  2706.       // ----- Update the informations
  2707.       // Nothing can be modified
  2708.     }
  2709.  
  2710.     // ----- Return
  2711.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2712.     return $v_result;
  2713.   }
  2714.   // --------------------------------------------------------------------------------
  2715.  
  2716.   // --------------------------------------------------------------------------------
  2717.   // Function : privCalculateStoredFilename()
  2718.   // Description :
  2719.   //   Based on file descriptor properties and global options, this method
  2720.   //   calculate the filename that will be stored in the archive.
  2721.   // Parameters :
  2722.   // Return Values :
  2723.   // --------------------------------------------------------------------------------
  2724.   function privCalculateStoredFilename(&$p_filedescr&$p_options)
  2725.   {
  2726.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCalculateStoredFilename", "filename='".$p_filedescr['filename']."'");
  2727.     $v_result=1;
  2728.     
  2729.     // ----- Working variables
  2730.     $p_filename $p_filedescr['filename'];
  2731.     if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
  2732.       $p_add_dir $p_options[PCLZIP_OPT_ADD_PATH];
  2733.     }
  2734.     else {
  2735.       $p_add_dir '';
  2736.     }
  2737.     if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
  2738.       $p_remove_dir $p_options[PCLZIP_OPT_REMOVE_PATH];
  2739.     }
  2740.     else {
  2741.       $p_remove_dir '';
  2742.     }
  2743.     if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  2744.       $p_remove_all_dir $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  2745.     }
  2746.     else {
  2747.       $p_remove_all_dir 0;
  2748.     }
  2749.  
  2750.     // ----- Look for full name change
  2751.     if (isset($p_filedescr['new_full_name'])) {
  2752.       $v_stored_filename $p_filedescr['new_full_name'];
  2753.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing full name of '".$p_filename."' for '".$v_stored_filename."'");
  2754.     }
  2755.     
  2756.     // ----- Look for path and/or short name change
  2757.     else {
  2758.  
  2759.       // ----- Look for short name change
  2760.       if (isset($p_filedescr['new_short_name'])) {
  2761.         $v_path_info pathinfo($p_filename);
  2762.         $v_dir '';
  2763.         if ($v_path_info['dirname'!= ''{
  2764.           $v_dir $v_path_info['dirname'].'/';
  2765.         }
  2766.         $v_stored_filename $v_dir.$p_filedescr['new_short_name'];
  2767.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Changing short name of '".$p_filename."' for '".$v_stored_filename."'");
  2768.       }
  2769.       else {
  2770.         // ----- Calculate the stored filename
  2771.         $v_stored_filename $p_filename;
  2772.       }
  2773.  
  2774.       // ----- Look for all path to remove
  2775.       if ($p_remove_all_dir{
  2776.         $v_stored_filename basename($p_filename);
  2777.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove all path selected change '".$p_filename."' for '".$v_stored_filename."'");
  2778.       }
  2779.       // ----- Look for partial path remove
  2780.       else if ($p_remove_dir != ""{
  2781.         if (substr($p_remove_dir-1!= '/')
  2782.           $p_remove_dir .= "/";
  2783.  
  2784.         if (   (substr($p_filename02== "./")
  2785.             || (substr($p_remove_dir02== "./")) {
  2786.             
  2787.           if (   (substr($p_filename02== "./")
  2788.               && (substr($p_remove_dir02!= "./")) {
  2789.             $p_remove_dir "./".$p_remove_dir;
  2790.           }
  2791.           if (   (substr($p_filename02!= "./")
  2792.               && (substr($p_remove_dir02== "./")) {
  2793.             $p_remove_dir substr($p_remove_dir2);
  2794.           }
  2795.         }
  2796.  
  2797.         $v_compare PclZipUtilPathInclusion($p_remove_dir,
  2798.                                              $v_stored_filename);
  2799.         if ($v_compare 0{
  2800.           if ($v_compare == 2{
  2801.             $v_stored_filename "";
  2802.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Path to remove is the current folder");
  2803.           }
  2804.           else {
  2805.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Remove path '$p_remove_dir' in file '$v_stored_filename'");
  2806.             $v_stored_filename substr($v_stored_filename,
  2807.                                         strlen($p_remove_dir));
  2808.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Result is '$v_stored_filename'");
  2809.           }
  2810.         }
  2811.       }
  2812.       // ----- Look for path to add
  2813.       if ($p_add_dir != ""{
  2814.         if (substr($p_add_dir-1== "/")
  2815.           $v_stored_filename $p_add_dir.$v_stored_filename;
  2816.         else
  2817.           $v_stored_filename $p_add_dir."/".$v_stored_filename;
  2818.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");
  2819.       }
  2820.     }
  2821.  
  2822.     // ----- Filename (reduce the path of stored name)
  2823.     $v_stored_filename PclZipUtilPathReduction($v_stored_filename);
  2824.     $p_filedescr['stored_filename'$v_stored_filename;
  2825.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Stored filename will be '".$p_filedescr['stored_filename']."', strlen ".strlen($p_filedescr['stored_filename']));
  2826.     
  2827.     // ----- Return
  2828.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2829.     return $v_result;
  2830.   }
  2831.   // --------------------------------------------------------------------------------
  2832.  
  2833.   // --------------------------------------------------------------------------------
  2834.   // Function : privWriteFileHeader()
  2835.   // Description :
  2836.   // Parameters :
  2837.   // Return Values :
  2838.   // --------------------------------------------------------------------------------
  2839.   function privWriteFileHeader(&$p_header)
  2840.   {
  2841.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');
  2842.     $v_result=1;
  2843.  
  2844.     // ----- Store the offset position of the file
  2845.     $p_header['offset'ftell($this->zip_fd);
  2846.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, 'File offset of the header :'.$p_header['offset']);
  2847.  
  2848.     // ----- Transform UNIX mtime to DOS format mdate/mtime
  2849.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
  2850.     $v_date getdate($p_header['mtime']);
  2851.     $v_mtime ($v_date['hours']<<11($v_date['minutes']<<5$v_date['seconds']/2;
  2852.     $v_mdate (($v_date['year']-1980)<<9($v_date['mon']<<5$v_date['mday'];
  2853.  
  2854.     // ----- Packed data
  2855.     $v_binary_data pack("VvvvvvVVVvv"0x04034b50,
  2856.                           $p_header['version_extracted']$p_header['flag'],
  2857.                           $p_header['compression']$v_mtime$v_mdate,
  2858.                           $p_header['crc']$p_header['compressed_size'],
  2859.                           $p_header['size'],
  2860.                           strlen($p_header['stored_filename']),
  2861.                           $p_header['extra_len']);
  2862.  
  2863.     // ----- Write the first 148 bytes of the header in the archive
  2864.     fputs($this->zip_fd$v_binary_data30);
  2865.  
  2866.     // ----- Write the variable fields
  2867.     if (strlen($p_header['stored_filename']!= 0)
  2868.     {
  2869.       fputs($this->zip_fd$p_header['stored_filename']strlen($p_header['stored_filename']));
  2870.     }
  2871.     if ($p_header['extra_len'!= 0)
  2872.     {
  2873.       fputs($this->zip_fd$p_header['extra']$p_header['extra_len']);
  2874.     }
  2875.  
  2876.     // ----- Return
  2877.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2878.     return $v_result;
  2879.   }
  2880.   // --------------------------------------------------------------------------------
  2881.  
  2882.   // --------------------------------------------------------------------------------
  2883.   // Function : privWriteCentralFileHeader()
  2884.   // Description :
  2885.   // Parameters :
  2886.   // Return Values :
  2887.   // --------------------------------------------------------------------------------
  2888.   function privWriteCentralFileHeader(&$p_header)
  2889.   {
  2890.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralFileHeader", 'file="'.$p_header['filename'].'", stored as "'.$p_header['stored_filename'].'"');
  2891.     $v_result=1;
  2892.  
  2893.     // TBC
  2894.     //for(reset($p_header); $key = key($p_header); next($p_header)) {
  2895.     //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "header[$key] = ".$p_header[$key]);
  2896.     //}
  2897.  
  2898.     // ----- Transform UNIX mtime to DOS format mdate/mtime
  2899.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
  2900.     $v_date getdate($p_header['mtime']);
  2901.     $v_mtime ($v_date['hours']<<11($v_date['minutes']<<5$v_date['seconds']/2;
  2902.     $v_mdate (($v_date['year']-1980)<<9($v_date['mon']<<5$v_date['mday'];
  2903.  
  2904.     // ----- Packed data
  2905.     $v_binary_data pack("VvvvvvvVVVvvvvvVV"0x02014b50,
  2906.                           $p_header['version']$p_header['version_extracted'],
  2907.                           $p_header['flag']$p_header['compression'],
  2908.                           $v_mtime$v_mdate$p_header['crc'],
  2909.                           $p_header['compressed_size']$p_header['size'],
  2910.                           strlen($p_header['stored_filename']),
  2911.                           $p_header['extra_len']$p_header['comment_len'],
  2912.                           $p_header['disk']$p_header['internal'],
  2913.                           $p_header['external']$p_header['offset']);
  2914.  
  2915.     // ----- Write the 42 bytes of the header in the zip file
  2916.     fputs($this->zip_fd$v_binary_data46);
  2917.  
  2918.     // ----- Write the variable fields
  2919.     if (strlen($p_header['stored_filename']!= 0)
  2920.     {
  2921.       fputs($this->zip_fd$p_header['stored_filename']strlen($p_header['stored_filename']));
  2922.     }
  2923.     if ($p_header['extra_len'!= 0)
  2924.     {
  2925.       fputs($this->zip_fd$p_header['extra']$p_header['extra_len']);
  2926.     }
  2927.     if ($p_header['comment_len'!= 0)
  2928.     {
  2929.       fputs($this->zip_fd$p_header['comment']$p_header['comment_len']);
  2930.     }
  2931.  
  2932.     // ----- Return
  2933.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2934.     return $v_result;
  2935.   }
  2936.   // --------------------------------------------------------------------------------
  2937.  
  2938.   // --------------------------------------------------------------------------------
  2939.   // Function : privWriteCentralHeader()
  2940.   // Description :
  2941.   // Parameters :
  2942.   // Return Values :
  2943.   // --------------------------------------------------------------------------------
  2944.   function privWriteCentralHeader($p_nb_entries$p_size$p_offset$p_comment)
  2945.   {
  2946.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privWriteCentralHeader", 'nb_entries='.$p_nb_entries.', size='.$p_size.', offset='.$p_offset.', comment="'.$p_comment.'"');
  2947.     $v_result=1;
  2948.  
  2949.     // ----- Packed data
  2950.     $v_binary_data pack("VvvvvVVv"0x06054b5000$p_nb_entries,
  2951.                           $p_nb_entries$p_size,
  2952.                           $p_offsetstrlen($p_comment));
  2953.  
  2954.     // ----- Write the 22 bytes of the header in the zip file
  2955.     fputs($this->zip_fd$v_binary_data22);
  2956.  
  2957.     // ----- Write the variable fields
  2958.     if (strlen($p_comment!= 0)
  2959.     {
  2960.       fputs($this->zip_fd$p_commentstrlen($p_comment));
  2961.     }
  2962.  
  2963.     // ----- Return
  2964.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  2965.     return $v_result;
  2966.   }
  2967.   // --------------------------------------------------------------------------------
  2968.  
  2969.   // --------------------------------------------------------------------------------
  2970.   // Function : privList()
  2971.   // Description :
  2972.   // Parameters :
  2973.   // Return Values :
  2974.   // --------------------------------------------------------------------------------
  2975.   function privList(&$p_list)
  2976.   {
  2977.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privList", "list");
  2978.     $v_result=1;
  2979.  
  2980.     // ----- Magic quotes trick
  2981.     $this->privDisableMagicQuotes();
  2982.  
  2983.     // ----- Open the zip file
  2984.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  2985.     if (($this->zip_fd = @fopen($this->zipname'rb')) == 0)
  2986.     {
  2987.       // ----- Magic quotes trick
  2988.       $this->privSwapBackMagicQuotes();
  2989.       
  2990.       // ----- Error log
  2991.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  2992.  
  2993.       // ----- Return
  2994.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  2995.       return PclZip::errorCode();
  2996.     }
  2997.  
  2998.     // ----- Read the central directory informations
  2999.     $v_central_dir array();
  3000.     if (($v_result $this->privReadEndCentralDir($v_central_dir)) != 1)
  3001.     {
  3002.       $this->privSwapBackMagicQuotes();
  3003.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3004.       return $v_result;
  3005.     }
  3006.  
  3007.     // ----- Go to beginning of Central Dir
  3008.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Offset : ".$v_central_dir['offset']."'");
  3009.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
  3010.     @rewind($this->zip_fd);
  3011.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
  3012.     if (@fseek($this->zip_fd$v_central_dir['offset']))
  3013.     {
  3014.       $this->privSwapBackMagicQuotes();
  3015.  
  3016.       // ----- Error log
  3017.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP'Invalid archive size');
  3018.  
  3019.       // ----- Return
  3020.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3021.       return PclZip::errorCode();
  3022.     }
  3023.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position in file : ".ftell($this->zip_fd)."'");
  3024.  
  3025.     // ----- Read each entry
  3026.     for ($i=0$i<$v_central_dir['entries']$i++)
  3027.     {
  3028.       // ----- Read the file header
  3029.       if (($v_result $this->privReadCentralFileHeader($v_header)) != 1)
  3030.       {
  3031.         $this->privSwapBackMagicQuotes();
  3032.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3033.         return $v_result;
  3034.       }
  3035.       $v_header['index'$i;
  3036.  
  3037.       // ----- Get the only interesting attributes
  3038.       $this->privConvertHeader2FileInfo($v_header$p_list[$i]);
  3039.       unset($v_header);
  3040.     }
  3041.  
  3042.     // ----- Close the zip file
  3043.     $this->privCloseFd();
  3044.  
  3045.     // ----- Magic quotes trick
  3046.     $this->privSwapBackMagicQuotes();
  3047.  
  3048.     // ----- Return
  3049.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3050.     return $v_result;
  3051.   }
  3052.   // --------------------------------------------------------------------------------
  3053.  
  3054.   // --------------------------------------------------------------------------------
  3055.   // Function : privConvertHeader2FileInfo()
  3056.   // Description :
  3057.   //   This function takes the file informations from the central directory
  3058.   //   entries and extract the interesting parameters that will be given back.
  3059.   //   The resulting file infos are set in the array $p_info
  3060.   //     $p_info['filename'] : Filename with full path. Given by user (add),
  3061.   //                           extracted in the filesystem (extract).
  3062.   //     $p_info['stored_filename'] : Stored filename in the archive.
  3063.   //     $p_info['size'] = Size of the file.
  3064.   //     $p_info['compressed_size'] = Compressed size of the file.
  3065.   //     $p_info['mtime'] = Last modification date of the file.
  3066.   //     $p_info['comment'] = Comment associated with the file.
  3067.   //     $p_info['folder'] = true/false : indicates if the entry is a folder or not.
  3068.   //     $p_info['status'] = status of the action on the file.
  3069.   // Parameters :
  3070.   // Return Values :
  3071.   // --------------------------------------------------------------------------------
  3072.   function privConvertHeader2FileInfo($p_header&$p_info)
  3073.   {
  3074.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privConvertHeader2FileInfo", "Filename='".$p_header['filename']."'");
  3075.     $v_result=1;
  3076.  
  3077.     // ----- Get the interesting attributes
  3078.     $p_info['filename'$p_header['filename'];
  3079.     $p_info['stored_filename'$p_header['stored_filename'];
  3080.     $p_info['size'$p_header['size'];
  3081.     $p_info['compressed_size'$p_header['compressed_size'];
  3082.     $p_info['mtime'$p_header['mtime'];
  3083.     $p_info['comment'$p_header['comment'];
  3084.     $p_info['folder'(($p_header['external']&0x00000010)==0x00000010);
  3085.     $p_info['index'$p_header['index'];
  3086.     $p_info['status'$p_header['status'];
  3087.  
  3088.     // ----- Return
  3089.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3090.     return $v_result;
  3091.   }
  3092.   // --------------------------------------------------------------------------------
  3093.  
  3094.   // --------------------------------------------------------------------------------
  3095.   // Function : privExtractByRule()
  3096.   // Description :
  3097.   //   Extract a file or directory depending of rules (by index, by name, ...)
  3098.   // Parameters :
  3099.   //   $p_file_list : An array where will be placed the properties of each
  3100.   //                  extracted file
  3101.   //   $p_path : Path to add while writing the extracted files
  3102.   //   $p_remove_path : Path to remove (from the file memorized path) while writing the
  3103.   //                    extracted files. If the path does not match the file path,
  3104.   //                    the file is extracted with its memorized path.
  3105.   //                    $p_remove_path does not apply to 'list' mode.
  3106.   //                    $p_path and $p_remove_path are commulative.
  3107.   // Return Values :
  3108.   //   1 on success,0 or less on error (see error code list)
  3109.   // --------------------------------------------------------------------------------
  3110.   function privExtractByRule(&$p_file_list$p_path$p_remove_path$p_remove_all_path&$p_options)
  3111.   {
  3112.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privExtractByRule", "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
  3113.     $v_result=1;
  3114.  
  3115.     // ----- Magic quotes trick
  3116.     $this->privDisableMagicQuotes();
  3117.  
  3118.     // ----- Check the path
  3119.     if (   ($p_path == "")
  3120.         || (   (substr($p_path01!= "/")
  3121.             && (substr($p_path03!= "../")
  3122.             && (substr($p_path,1,2)!=":/")))
  3123.       $p_path "./".$p_path;
  3124.  
  3125.     // ----- Reduce the path last (and duplicated) '/'
  3126.     if (($p_path != "./"&& ($p_path != "/"))
  3127.     {
  3128.       // ----- Look for the path end '/'
  3129.       while (substr($p_path-1== "/")
  3130.       {
  3131.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
  3132.         $p_path substr($p_path0strlen($p_path)-1);
  3133.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
  3134.       }
  3135.     }
  3136.  
  3137.     // ----- Look for path to remove format (should end by /)
  3138.     if (($p_remove_path != ""&& (substr($p_remove_path-1!= '/'))
  3139.     {
  3140.       $p_remove_path .= '/';
  3141.     }
  3142.     $p_remove_path_size strlen($p_remove_path);
  3143.  
  3144.     // ----- Open the zip file
  3145.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  3146.     if (($v_result $this->privOpenFd('rb')) != 1)
  3147.     {
  3148.       $this->privSwapBackMagicQuotes();
  3149.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3150.       return $v_result;
  3151.     }
  3152.  
  3153.     // ----- Read the central directory informations
  3154.     $v_central_dir array();
  3155.     if (($v_result $this->privReadEndCentralDir($v_central_dir)) != 1)
  3156.     {
  3157.       // ----- Close the zip file
  3158.       $this->privCloseFd();
  3159.       $this->privSwapBackMagicQuotes();
  3160.  
  3161.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3162.       return $v_result;
  3163.     }
  3164.  
  3165.     // ----- Start at beginning of Central Dir
  3166.     $v_pos_entry $v_central_dir['offset'];
  3167.  
  3168.     // ----- Read each entry
  3169.     $j_start 0;
  3170.     for ($i=0$v_nb_extracted=0$i<$v_central_dir['entries']$i++)
  3171.     {
  3172.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry : '$i'");
  3173.  
  3174.       // ----- Read next Central dir entry
  3175.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position before rewind : ".ftell($this->zip_fd)."'");
  3176.       @rewind($this->zip_fd);
  3177.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Position after rewind : ".ftell($this->zip_fd)."'");
  3178.       if (@fseek($this->zip_fd$v_pos_entry))
  3179.       {
  3180.         // ----- Close the zip file
  3181.         $this->privCloseFd();
  3182.         $this->privSwapBackMagicQuotes();
  3183.  
  3184.         // ----- Error log
  3185.         PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP'Invalid archive size');
  3186.  
  3187.         // ----- Return
  3188.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3189.         return PclZip::errorCode();
  3190.       }
  3191.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Position after fseek : ".ftell($this->zip_fd)."'");
  3192.  
  3193.       // ----- Read the file header
  3194.       $v_header array();
  3195.       if (($v_result $this->privReadCentralFileHeader($v_header)) != 1)
  3196.       {
  3197.         // ----- Close the zip file
  3198.         $this->privCloseFd();
  3199.         $this->privSwapBackMagicQuotes();
  3200.  
  3201.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3202.         return $v_result;
  3203.       }
  3204.  
  3205.       // ----- Store the index
  3206.       $v_header['index'$i;
  3207.  
  3208.       // ----- Store the file position
  3209.       $v_pos_entry ftell($this->zip_fd);
  3210.  
  3211.       // ----- Look for the specific extract rules
  3212.       $v_extract false;
  3213.  
  3214.       // ----- Look for extract by name rule
  3215.       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
  3216.           && ($p_options[PCLZIP_OPT_BY_NAME!= 0)) {
  3217.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
  3218.  
  3219.           // ----- Look if the filename is in the list
  3220.           for ($j=0($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract)$j++{
  3221.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
  3222.  
  3223.               // ----- Look for a directory
  3224.               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j]-1== "/"{
  3225.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
  3226.  
  3227.                   // ----- Look if the directory is in the filename path
  3228.                   if (   (strlen($v_header['stored_filename']strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
  3229.                       && (substr($v_header['stored_filename']0strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  3230.                       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
  3231.                       $v_extract true;
  3232.                   }
  3233.               }
  3234.               // ----- Look for a filename
  3235.               elseif ($v_header['stored_filename'== $p_options[PCLZIP_OPT_BY_NAME][$j]{
  3236.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
  3237.                   $v_extract true;
  3238.               }
  3239.           }
  3240.       }
  3241.  
  3242.       // ----- Look for extract by ereg rule
  3243.       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
  3244.                && ($p_options[PCLZIP_OPT_BY_EREG!= "")) {
  3245.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
  3246.  
  3247.           if (ereg($p_options[PCLZIP_OPT_BY_EREG]$v_header['stored_filename'])) {
  3248.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
  3249.               $v_extract true;
  3250.           }
  3251.       }
  3252.  
  3253.       // ----- Look for extract by preg rule
  3254.       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
  3255.                && ($p_options[PCLZIP_OPT_BY_PREG!= "")) {
  3256.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
  3257.  
  3258.           if (preg_match($p_options[PCLZIP_OPT_BY_PREG]$v_header['stored_filename'])) {
  3259.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
  3260.               $v_extract true;
  3261.           }
  3262.       }
  3263.  
  3264.       // ----- Look for extract by index rule
  3265.       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
  3266.                && ($p_options[PCLZIP_OPT_BY_INDEX!= 0)) {
  3267.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
  3268.           
  3269.           // ----- Look if the index is in the list
  3270.           for ($j=$j_start($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract)$j++{
  3271.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");
  3272.  
  3273.               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']&& ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  3274.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
  3275.                   $v_extract true;
  3276.               }
  3277.               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']{
  3278.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");
  3279.                   $j_start $j+1;
  3280.               }
  3281.  
  3282.               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i{
  3283.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");
  3284.                   break;
  3285.               }
  3286.           }
  3287.       }
  3288.  
  3289.       // ----- Look for no rule, which means extract all the archive
  3290.       else {
  3291.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with no rule (extract all)");
  3292.           $v_extract true;
  3293.       }
  3294.  
  3295.       // ----- Check compression method
  3296.       if (   ($v_extract)
  3297.           && (   ($v_header['compression'!= 8)
  3298.               && ($v_header['compression'!= 0))) {
  3299.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported compression method (".$v_header['compression'].")");
  3300.           $v_header['status''unsupported_compression';
  3301.  
  3302.           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
  3303.           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  3304.               && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  3305.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
  3306.  
  3307.               $this->privSwapBackMagicQuotes();
  3308.               
  3309.                                    "Filename '".$v_header['stored_filename']."' is "
  3310.                                        ."compressed by an unsupported compression "
  3311.                                        ."method (".$v_header['compression'].") ");
  3312.  
  3313.               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3314.               return PclZip::errorCode();
  3315.           }
  3316.       }
  3317.       
  3318.       // ----- Check encrypted files
  3319.       if (($v_extract&& (($v_header['flag'1== 1)) {
  3320.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unsupported file encryption");
  3321.           $v_header['status''unsupported_encryption';
  3322.  
  3323.           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
  3324.           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  3325.               && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  3326.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
  3327.  
  3328.               $this->privSwapBackMagicQuotes();
  3329.  
  3330.                                    "Unsupported encryption for "
  3331.                                        ." filename '".$v_header['stored_filename']
  3332.                                    ."'");
  3333.  
  3334.               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3335.               return PclZip::errorCode();
  3336.           }
  3337.     }
  3338.  
  3339.       // ----- Look for real extraction
  3340.       if (($v_extract&& ($v_header['status'!= 'ok')) {
  3341.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "No need for extract");
  3342.           $v_result $this->privConvertHeader2FileInfo($v_header,
  3343.                                                 $p_file_list[$v_nb_extracted++]);
  3344.           if ($v_result != 1{
  3345.               $this->privCloseFd();
  3346.               $this->privSwapBackMagicQuotes();
  3347.               //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3348.               return $v_result;
  3349.           }
  3350.  
  3351.           $v_extract false;
  3352.       }
  3353.       
  3354.       // ----- Look for real extraction
  3355.       if ($v_extract)
  3356.       {
  3357.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file '".$v_header['filename']."', index '$i'");
  3358.  
  3359.         // ----- Go to the file position
  3360.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
  3361.         @rewind($this->zip_fd);
  3362.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
  3363.         if (@fseek($this->zip_fd$v_header['offset']))
  3364.         {
  3365.           // ----- Close the zip file
  3366.           $this->privCloseFd();
  3367.  
  3368.           $this->privSwapBackMagicQuotes();
  3369.  
  3370.           // ----- Error log
  3371.           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP'Invalid archive size');
  3372.  
  3373.           // ----- Return
  3374.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3375.           return PclZip::errorCode();
  3376.         }
  3377.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
  3378.  
  3379.         // ----- Look for extraction as string
  3380.         if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]{
  3381.  
  3382.           // ----- Extracting the file
  3383.           $v_result1 $this->privExtractFileAsString($v_header$v_string);
  3384.           if ($v_result1 1{
  3385.             $this->privCloseFd();
  3386.             $this->privSwapBackMagicQuotes();
  3387.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
  3388.             return $v_result1;
  3389.           }
  3390.  
  3391.           // ----- Get the only interesting attributes
  3392.           if (($v_result $this->privConvertHeader2FileInfo($v_header$p_file_list[$v_nb_extracted])) != 1)
  3393.           {
  3394.             // ----- Close the zip file
  3395.             $this->privCloseFd();
  3396.             $this->privSwapBackMagicQuotes();
  3397.  
  3398.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3399.             return $v_result;
  3400.           }
  3401.  
  3402.           // ----- Set the file content
  3403.           $p_file_list[$v_nb_extracted]['content'$v_string;
  3404.  
  3405.           // ----- Next extracted file
  3406.           $v_nb_extracted++;
  3407.           
  3408.           // ----- Look for user callback abort
  3409.           if ($v_result1 == 2{
  3410.               break;
  3411.           }
  3412.         }
  3413.         // ----- Look for extraction in standard output
  3414.         elseif (   (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
  3415.                 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
  3416.           // ----- Extracting the file in standard output
  3417.           $v_result1 $this->privExtractFileInOutput($v_header$p_options);
  3418.           if ($v_result1 1{
  3419.             $this->privCloseFd();
  3420.             $this->privSwapBackMagicQuotes();
  3421.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
  3422.             return $v_result1;
  3423.           }
  3424.  
  3425.           // ----- Get the only interesting attributes
  3426.           if (($v_result $this->privConvertHeader2FileInfo($v_header$p_file_list[$v_nb_extracted++])) != 1{
  3427.             $this->privCloseFd();
  3428.             $this->privSwapBackMagicQuotes();
  3429.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3430.             return $v_result;
  3431.           }
  3432.  
  3433.           // ----- Look for user callback abort
  3434.           if ($v_result1 == 2{
  3435.               break;
  3436.           }
  3437.         }
  3438.         // ----- Look for normal extraction
  3439.         else {
  3440.           // ----- Extracting the file
  3441.           $v_result1 $this->privExtractFile($v_header,
  3442.                                               $p_path$p_remove_path,
  3443.                                               $p_remove_all_path,
  3444.                                               $p_options);
  3445.           if ($v_result1 1{
  3446.             $this->privCloseFd();
  3447.             $this->privSwapBackMagicQuotes();
  3448.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result1);
  3449.             return $v_result1;
  3450.           }
  3451.  
  3452.           // ----- Get the only interesting attributes
  3453.           if (($v_result $this->privConvertHeader2FileInfo($v_header$p_file_list[$v_nb_extracted++])) != 1)
  3454.           {
  3455.             // ----- Close the zip file
  3456.             $this->privCloseFd();
  3457.             $this->privSwapBackMagicQuotes();
  3458.  
  3459.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3460.             return $v_result;
  3461.           }
  3462.  
  3463.           // ----- Look for user callback abort
  3464.           if ($v_result1 == 2{
  3465.               break;
  3466.           }
  3467.         }
  3468.       }
  3469.     }
  3470.  
  3471.     // ----- Close the zip file
  3472.     $this->privCloseFd();
  3473.     $this->privSwapBackMagicQuotes();
  3474.  
  3475.     // ----- Return
  3476.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3477.     return $v_result;
  3478.   }
  3479.   // --------------------------------------------------------------------------------
  3480.  
  3481.   // --------------------------------------------------------------------------------
  3482.   // Function : privExtractFile()
  3483.   // Description :
  3484.   // Parameters :
  3485.   // Return Values :
  3486.   //
  3487.   // 1 : ... ?
  3488.   // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
  3489.   // --------------------------------------------------------------------------------
  3490.   function privExtractFile(&$p_entry$p_path$p_remove_path$p_remove_all_path&$p_options)
  3491.   {
  3492.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
  3493.     $v_result=1;
  3494.  
  3495.     // ----- Read the file header
  3496.     if (($v_result $this->privReadFileHeader($v_header)) != 1)
  3497.     {
  3498.       // ----- Return
  3499.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3500.       return $v_result;
  3501.     }
  3502.  
  3503.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
  3504.  
  3505.     // ----- Check that the file header is coherent with $p_entry info
  3506.     if ($this->privCheckFileHeaders($v_header$p_entry!= 1{
  3507.         // TBC
  3508.     }
  3509.  
  3510.     // ----- Look for all path to remove
  3511.     if ($p_remove_all_path == true{
  3512.         // ----- Look for folder entry that not need to be extracted
  3513.         if (($p_entry['external']&0x00000010)==0x00000010{
  3514.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered");
  3515.  
  3516.             $p_entry['status'"filtered";
  3517.  
  3518.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3519.             return $v_result;
  3520.         }
  3521.  
  3522.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed");
  3523.         // ----- Get the basename of the path
  3524.         $p_entry['filename'basename($p_entry['filename']);
  3525.     }
  3526.  
  3527.     // ----- Look for path to remove
  3528.     else if ($p_remove_path != "")
  3529.     {
  3530.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove");
  3531.       if (PclZipUtilPathInclusion($p_remove_path$p_entry['filename']== 2)
  3532.       {
  3533.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");
  3534.  
  3535.         // ----- Change the file status
  3536.         $p_entry['status'"filtered";
  3537.  
  3538.         // ----- Return
  3539.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3540.         return $v_result;
  3541.       }
  3542.  
  3543.       $p_remove_path_size strlen($p_remove_path);
  3544.       if (substr($p_entry['filename']0$p_remove_path_size== $p_remove_path)
  3545.       {
  3546.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");
  3547.  
  3548.         // ----- Remove the path
  3549.         $p_entry['filename'substr($p_entry['filename']$p_remove_path_size);
  3550.  
  3551.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");
  3552.       }
  3553.     }
  3554.  
  3555.     // ----- Add the path
  3556.     if ($p_path != ''{
  3557.       $p_entry['filename'$p_path."/".$p_entry['filename'];
  3558.     }
  3559.     
  3560.     // ----- Check a base_dir_restriction
  3561.     if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
  3562.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction");
  3563.       $v_inclusion
  3564.                                 $p_entry['filename'])
  3565.       if ($v_inclusion == 0{
  3566.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction");
  3567.  
  3568.                                  "Filename '".$p_entry['filename']."' is "
  3569.                                  ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
  3570.  
  3571.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3572.         return PclZip::errorCode();
  3573.       }
  3574.     }
  3575.  
  3576.     // ----- Look for pre-extract callback
  3577.     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  3578.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
  3579.  
  3580.       // ----- Generate a local information
  3581.       $v_local_header array();
  3582.       $this->privConvertHeader2FileInfo($p_entry$v_local_header);
  3583.  
  3584.       // ----- Call the callback
  3585.       // Here I do not use call_user_func() because I need to send a reference to the
  3586.       // header.
  3587.       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
  3588.       if ($v_result == 0{
  3589.         // ----- Change the file status
  3590.         $p_entry['status'"skipped";
  3591.         $v_result 1;
  3592.       }
  3593.       
  3594.       // ----- Look for abort result
  3595.       if ($v_result == 2{
  3596.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
  3597.         // ----- This status is internal and will be changed in 'skipped'
  3598.         $p_entry['status'"aborted";
  3599.           $v_result PCLZIP_ERR_USER_ABORTED;
  3600.       }
  3601.  
  3602.       // ----- Update the informations
  3603.       // Only some fields can be modified
  3604.       $p_entry['filename'$v_local_header['filename'];
  3605.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
  3606.     }
  3607.  
  3608.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
  3609.  
  3610.     // ----- Look if extraction should be done
  3611.     if ($p_entry['status'== 'ok'{
  3612.  
  3613.     // ----- Look for specific actions while the file exist
  3614.     if (file_exists($p_entry['filename']))
  3615.     {
  3616.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");
  3617.  
  3618.       // ----- Look if file is a directory
  3619.       if (is_dir($p_entry['filename']))
  3620.       {
  3621.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");
  3622.  
  3623.         // ----- Change the file status
  3624.         $p_entry['status'"already_a_directory";
  3625.         
  3626.         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
  3627.         // For historical reason first PclZip implementation does not stop
  3628.         // when this kind of error occurs.
  3629.         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  3630.             && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  3631.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
  3632.  
  3633.                                  "Filename '".$p_entry['filename']."' is "
  3634.                                  ."already used by an existing directory");
  3635.  
  3636.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3637.             return PclZip::errorCode();
  3638.         }
  3639.       }
  3640.       // ----- Look if file is write protected
  3641.       else if (!is_writeable($p_entry['filename']))
  3642.       {
  3643.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected");
  3644.  
  3645.         // ----- Change the file status
  3646.         $p_entry['status'"write_protected";
  3647.  
  3648.         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
  3649.         // For historical reason first PclZip implementation does not stop
  3650.         // when this kind of error occurs.
  3651.         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  3652.             && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  3653.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
  3654.  
  3655.                                  "Filename '".$p_entry['filename']."' exists "
  3656.                                  ."and is write protected");
  3657.  
  3658.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3659.             return PclZip::errorCode();
  3660.         }
  3661.       }
  3662.  
  3663.       // ----- Look if the extracted file is older
  3664.       else if (filemtime($p_entry['filename']$p_entry['mtime'])
  3665.       {
  3666.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")");
  3667.         // ----- Change the file status
  3668.         if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
  3669.             && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
  3670.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_REPLACE_NEWER is selected, file will be replaced");
  3671.         }
  3672.         else {
  3673.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File will not be replaced");
  3674.             $p_entry['status'"newer_exist";
  3675.  
  3676.             // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
  3677.             // For historical reason first PclZip implementation does not stop
  3678.             // when this kind of error occurs.
  3679.             if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  3680.                 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  3681.                 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_STOP_ON_ERROR is selected, extraction will be stopped");
  3682.  
  3683.                 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
  3684.                          "Newer version of '".$p_entry['filename']."' exists "
  3685.                         ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
  3686.  
  3687.                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  3688.                 return PclZip::errorCode();
  3689.             }
  3690.         }
  3691.       }
  3692.       else {
  3693.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is older than the extrated one - will be replaced by the extracted one (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")");
  3694.       }
  3695.     }
  3696.  
  3697.     // ----- Check the directory availability and create it if necessary
  3698.     else {
  3699.       if ((($p_entry['external']&0x00000010)==0x00000010|| (substr($p_entry['filename']-1== '/'))
  3700.         $v_dir_to_check $p_entry['filename'];
  3701.       else if (!strstr($p_entry['filename']"/"))
  3702.         $v_dir_to_check "";
  3703.       else
  3704.         $v_dir_to_check dirname($p_entry['filename']);
  3705.  
  3706.       if (($v_result $this->privDirCheck($v_dir_to_check(($p_entry['external']&0x00000010)==0x00000010))) != 1{
  3707.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '".$p_entry['filename']."'");
  3708.  
  3709.         // ----- Change the file status
  3710.         $p_entry['status'"path_creation_fail";
  3711.  
  3712.         // ----- Return
  3713.         ////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3714.         //return $v_result;
  3715.         $v_result 1;
  3716.       }
  3717.     }
  3718.     }
  3719.  
  3720.     // ----- Look if extraction should be done
  3721.     if ($p_entry['status'== 'ok'{
  3722.  
  3723.       // ----- Do the extraction (if not a folder)
  3724.       if (!(($p_entry['external']&0x00000010)==0x00000010))
  3725.       {
  3726.         // ----- Look for not compressed file
  3727.         if ($p_entry['compression'== 0{
  3728.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
  3729.  
  3730.           // ----- Opening destination file
  3731.           if (($v_dest_file @fopen($p_entry['filename']'wb')) == 0)
  3732.           {
  3733.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");
  3734.  
  3735.             // ----- Change the file status
  3736.             $p_entry['status'"write_error";
  3737.  
  3738.             // ----- Return
  3739.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3740.             return $v_result;
  3741.           }
  3742.  
  3743.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read '".$p_entry['size']."' bytes");
  3744.  
  3745.           // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
  3746.           $v_size $p_entry['compressed_size'];
  3747.           while ($v_size != 0)
  3748.           {
  3749.             $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  3750.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Read $v_read_size bytes");
  3751.             $v_buffer @fread($this->zip_fd$v_read_size);
  3752.             /* Try to speed up the code
  3753.             $v_binary_data = pack('a'.$v_read_size, $v_buffer);
  3754.             @fwrite($v_dest_file, $v_binary_data, $v_read_size);
  3755.             */
  3756.             @fwrite($v_dest_file$v_buffer$v_read_size);            
  3757.             $v_size -= $v_read_size;
  3758.           }
  3759.  
  3760.           // ----- Closing the destination file
  3761.           fclose($v_dest_file);
  3762.  
  3763.           // ----- Change the file mtime
  3764.           touch($p_entry['filename']$p_entry['mtime']);
  3765.           
  3766.  
  3767.         }
  3768.         else {
  3769.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (Compression method ".$p_entry['compression'].")");
  3770.           // ----- TBC
  3771.           // Need to be finished
  3772.           if (($p_entry['flag'1== 1{
  3773.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File is encrypted");
  3774.             /*
  3775.               // ----- Read the encryption header
  3776.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read 12 encryption header bytes");
  3777.               $v_encryption_header = @fread($this->zip_fd, 12);
  3778.               
  3779.               // ----- Read the encrypted & compressed file in a buffer
  3780.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".($p_entry['compressed_size']-12)."' compressed & encrypted bytes");
  3781.               $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']-12);
  3782.               
  3783.               // ----- Decrypt the buffer
  3784.               $this->privDecrypt($v_encryption_header, $v_buffer,
  3785.                                  $p_entry['compressed_size']-12, $p_entry['crc']);
  3786.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Buffer is '".$v_buffer."'");
  3787.               */
  3788.           }
  3789.           else {
  3790.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read '".$p_entry['compressed_size']."' compressed bytes");
  3791.               // ----- Read the compressed file in a buffer (one shot)
  3792.               $v_buffer @fread($this->zip_fd$p_entry['compressed_size']);
  3793.           }
  3794.           
  3795.           // ----- Decompress the file
  3796.           $v_file_content @gzinflate($v_buffer);
  3797.           unset($v_buffer);
  3798.           if ($v_file_content === FALSE{
  3799.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to inflate compressed file");
  3800.  
  3801.             // ----- Change the file status
  3802.             // TBC
  3803.             $p_entry['status'"error";
  3804.             
  3805.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3806.             return $v_result;
  3807.           }
  3808.           
  3809.           // ----- Opening destination file
  3810.           if (($v_dest_file @fopen($p_entry['filename']'wb')) == 0{
  3811.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Error while opening '".$p_entry['filename']."' in write binary mode");
  3812.  
  3813.             // ----- Change the file status
  3814.             $p_entry['status'"write_error";
  3815.  
  3816.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3817.             return $v_result;
  3818.           }
  3819.  
  3820.           // ----- Write the uncompressed data
  3821.           @fwrite($v_dest_file$v_file_content$p_entry['size']);
  3822.           unset($v_file_content);
  3823.  
  3824.           // ----- Closing the destination file
  3825.           @fclose($v_dest_file);
  3826.  
  3827.           // ----- Change the file mtime
  3828.           @touch($p_entry['filename']$p_entry['mtime']);
  3829.         }
  3830.  
  3831.         // ----- Look for chmod option
  3832.         if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
  3833.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "chmod option activated '".$p_options[PCLZIP_OPT_SET_CHMOD]."'");
  3834.  
  3835.           // ----- Change the mode of the file
  3836.           @chmod($p_entry['filename']$p_options[PCLZIP_OPT_SET_CHMOD]);
  3837.         }
  3838.  
  3839.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
  3840.       }
  3841.     }
  3842.  
  3843.     // ----- Change abort status
  3844.     if ($p_entry['status'== "aborted"{
  3845.       $p_entry['status'"skipped";
  3846.     }
  3847.     
  3848.     // ----- Look for post-extract callback
  3849.     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  3850.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");
  3851.  
  3852.       // ----- Generate a local information
  3853.       $v_local_header array();
  3854.       $this->privConvertHeader2FileInfo($p_entry$v_local_header);
  3855.  
  3856.       // ----- Call the callback
  3857.       // Here I do not use call_user_func() because I need to send a reference to the
  3858.       // header.
  3859.       eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
  3860.  
  3861.       // ----- Look for abort result
  3862.       if ($v_result == 2{
  3863.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
  3864.           $v_result PCLZIP_ERR_USER_ABORTED;
  3865.       }
  3866.     }
  3867.  
  3868.     // ----- Return
  3869.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3870.     return $v_result;
  3871.   }
  3872.   // --------------------------------------------------------------------------------
  3873.  
  3874.   // --------------------------------------------------------------------------------
  3875.   // Function : privExtractFileInOutput()
  3876.   // Description :
  3877.   // Parameters :
  3878.   // Return Values :
  3879.   // --------------------------------------------------------------------------------
  3880.   function privExtractFileInOutput(&$p_entry&$p_options)
  3881.   {
  3882.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileInOutput', "");
  3883.     $v_result=1;
  3884.  
  3885.     // ----- Read the file header
  3886.     if (($v_result $this->privReadFileHeader($v_header)) != 1{
  3887.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3888.       return $v_result;
  3889.     }
  3890.  
  3891.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
  3892.  
  3893.     // ----- Check that the file header is coherent with $p_entry info
  3894.     if ($this->privCheckFileHeaders($v_header$p_entry!= 1{
  3895.         // TBC
  3896.     }
  3897.  
  3898.     // ----- Look for pre-extract callback
  3899.     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  3900.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
  3901.  
  3902.       // ----- Generate a local information
  3903.       $v_local_header array();
  3904.       $this->privConvertHeader2FileInfo($p_entry$v_local_header);
  3905.  
  3906.       // ----- Call the callback
  3907.       // Here I do not use call_user_func() because I need to send a reference to the
  3908.       // header.
  3909.       eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
  3910.       if ($v_result == 0{
  3911.         // ----- Change the file status
  3912.         $p_entry['status'"skipped";
  3913.         $v_result 1;
  3914.       }
  3915.  
  3916.       // ----- Look for abort result
  3917.       if ($v_result == 2{
  3918.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
  3919.         // ----- This status is internal and will be changed in 'skipped'
  3920.         $p_entry['status'"aborted";
  3921.           $v_result PCLZIP_ERR_USER_ABORTED;
  3922.       }
  3923.  
  3924.       // ----- Update the informations
  3925.       // Only some fields can be modified
  3926.       $p_entry['filename'$v_local_header['filename'];
  3927.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
  3928.     }
  3929.  
  3930.     // ----- Trace
  3931.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
  3932.  
  3933.     // ----- Look if extraction should be done
  3934.     if ($p_entry['status'== 'ok'{
  3935.  
  3936.       // ----- Do the extraction (if not a folder)
  3937.       if (!(($p_entry['external']&0x00000010)==0x00000010)) {
  3938.         // ----- Look for not compressed file
  3939.         if ($p_entry['compressed_size'== $p_entry['size']{
  3940.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
  3941.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");
  3942.  
  3943.           // ----- Read the file in a buffer (one shot)
  3944.           $v_buffer @fread($this->zip_fd$p_entry['compressed_size']);
  3945.  
  3946.           // ----- Send the file to the output
  3947.           echo $v_buffer;
  3948.           unset($v_buffer);
  3949.         }
  3950.         else {
  3951.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file");
  3952.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Reading '".$p_entry['size']."' bytes");
  3953.  
  3954.           // ----- Read the compressed file in a buffer (one shot)
  3955.           $v_buffer @fread($this->zip_fd$p_entry['compressed_size']);
  3956.           
  3957.           // ----- Decompress the file
  3958.           $v_file_content gzinflate($v_buffer);
  3959.           unset($v_buffer);
  3960.  
  3961.           // ----- Send the file to the output
  3962.           echo $v_file_content;
  3963.           unset($v_file_content);
  3964.         }
  3965.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
  3966.       }
  3967.     }
  3968.  
  3969.     // ----- Change abort status
  3970.     if ($p_entry['status'== "aborted"{
  3971.       $p_entry['status'"skipped";
  3972.     }
  3973.  
  3974.     // ----- Look for post-extract callback
  3975.     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  3976.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A post-callback '".$p_options[PCLZIP_CB_POST_EXTRACT]."()') is defined for the extraction");
  3977.  
  3978.       // ----- Generate a local information
  3979.       $v_local_header array();
  3980.       $this->privConvertHeader2FileInfo($p_entry$v_local_header);
  3981.  
  3982.       // ----- Call the callback
  3983.       // Here I do not use call_user_func() because I need to send a reference to the
  3984.       // header.
  3985.       eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
  3986.  
  3987.       // ----- Look for abort result
  3988.       if ($v_result == 2{
  3989.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
  3990.           $v_result PCLZIP_ERR_USER_ABORTED;
  3991.       }
  3992.     }
  3993.  
  3994.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  3995.     return $v_result;
  3996.   }
  3997.   // --------------------------------------------------------------------------------
  3998.  
  3999.   // --------------------------------------------------------------------------------
  4000.   // Function : privExtractFileAsString()
  4001.   // Description :
  4002.   // Parameters :
  4003.   // Return Values :
  4004.   // --------------------------------------------------------------------------------
  4005.   function privExtractFileAsString(&$p_entry&$p_string)
  4006.   {
  4007.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFileAsString', "p_entry['filename']='".$p_entry['filename']."'");
  4008.     $v_result=1;
  4009.  
  4010.     // ----- Read the file header
  4011.     $v_header array();
  4012.     if (($v_result $this->privReadFileHeader($v_header)) != 1)
  4013.     {
  4014.       // ----- Return
  4015.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4016.       return $v_result;
  4017.     }
  4018.  
  4019.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
  4020.  
  4021.     // ----- Check that the file header is coherent with $p_entry info
  4022.     if ($this->privCheckFileHeaders($v_header$p_entry!= 1{
  4023.         // TBC
  4024.     }
  4025.  
  4026.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file in string (with path) '".$p_entry['filename']."', size '$v_header[size]'");
  4027.  
  4028.     // ----- Do the extraction (if not a folder)
  4029.     if (!(($p_entry['external']&0x00000010)==0x00000010))
  4030.     {
  4031.       // ----- Look for not compressed file
  4032. //      if ($p_entry['compressed_size'] == $p_entry['size'])
  4033.       if ($p_entry['compression'== 0{
  4034.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting an un-compressed file");
  4035.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Reading '".$p_entry['size']."' bytes");
  4036.  
  4037.         // ----- Reading the file
  4038.         $p_string @fread($this->zip_fd$p_entry['compressed_size']);
  4039.       }
  4040.       else {
  4041.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting a compressed file (compression method '".$p_entry['compression']."')");
  4042.  
  4043.         // ----- Reading the file
  4044.         $v_data @fread($this->zip_fd$p_entry['compressed_size']);
  4045.         
  4046.         // ----- Decompress the file
  4047.         if (($p_string @gzinflate($v_data)) === FALSE{
  4048.             // TBC
  4049.         }
  4050.       }
  4051.  
  4052.       // ----- Trace
  4053.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extraction done");
  4054.     }
  4055.     else {
  4056.         // TBC : error : can not extract a folder in a string
  4057.     }
  4058.  
  4059.     // ----- Return
  4060.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4061.     return $v_result;
  4062.   }
  4063.   // --------------------------------------------------------------------------------
  4064.  
  4065.   // --------------------------------------------------------------------------------
  4066.   // Function : privReadFileHeader()
  4067.   // Description :
  4068.   // Parameters :
  4069.   // Return Values :
  4070.   // --------------------------------------------------------------------------------
  4071.   function privReadFileHeader(&$p_header)
  4072.   {
  4073.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadFileHeader", "");
  4074.     $v_result=1;
  4075.  
  4076.     // ----- Read the 4 bytes signature
  4077.     $v_binary_data @fread($this->zip_fd4);
  4078.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
  4079.     $v_data unpack('Vid'$v_binary_data);
  4080.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
  4081.  
  4082.     // ----- Check signature
  4083.     if ($v_data['id'!= 0x04034b50)
  4084.     {
  4085.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid File header");
  4086.  
  4087.       // ----- Error log
  4088.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT'Invalid archive structure');
  4089.  
  4090.       // ----- Return
  4091.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4092.       return PclZip::errorCode();
  4093.     }
  4094.  
  4095.     // ----- Read the first 42 bytes of the header
  4096.     $v_binary_data fread($this->zip_fd26);
  4097.  
  4098.     // ----- Look for invalid block size
  4099.     if (strlen($v_binary_data!= 26)
  4100.     {
  4101.       $p_header['filename'"";
  4102.       $p_header['status'"invalid_header";
  4103.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));
  4104.  
  4105.       // ----- Error log
  4106.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT"Invalid block size : ".strlen($v_binary_data));
  4107.  
  4108.       // ----- Return
  4109.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4110.       return PclZip::errorCode();
  4111.     }
  4112.  
  4113.     // ----- Extract the values
  4114.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header : '".$v_binary_data."'");
  4115.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Header (Hex) : '".bin2hex($v_binary_data)."'");
  4116.     $v_data unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len'$v_binary_data);
  4117.  
  4118.     // ----- Get filename
  4119.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "File name length : ".$v_data['filename_len']);
  4120.     $p_header['filename'fread($this->zip_fd$v_data['filename_len']);
  4121.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename : \''.$p_header['filename'].'\'');
  4122.  
  4123.     // ----- Get extra_fields
  4124.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extra field length : ".$v_data['extra_len']);
  4125.     if ($v_data['extra_len'!= 0{
  4126.       $p_header['extra'fread($this->zip_fd$v_data['extra_len']);
  4127.     }
  4128.     else {
  4129.       $p_header['extra''';
  4130.     }
  4131.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Extra field : \''.bin2hex($p_header['extra']).'\'');
  4132.  
  4133.     // ----- Extract properties
  4134.     $p_header['version_extracted'$v_data['version'];
  4135.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : ('.$p_header['version_extracted'].') \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');
  4136.     $p_header['compression'$v_data['compression'];
  4137.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compression method : \''.$p_header['compression'].'\'');
  4138.     $p_header['size'$v_data['size'];
  4139.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_header['size'].'\'');
  4140.     $p_header['compressed_size'$v_data['compressed_size'];
  4141.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_header['compressed_size'].'\'');
  4142.     $p_header['crc'$v_data['crc'];
  4143.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');
  4144.     $p_header['flag'$v_data['flag'];
  4145.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Flag : \''.$p_header['flag'].'\'');
  4146.     $p_header['filename_len'$v_data['filename_len'];
  4147.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Filename_len : \''.$p_header['filename_len'].'\'');
  4148.  
  4149.     // ----- Recuperate date in UNIX format
  4150.     $p_header['mdate'$v_data['mdate'];
  4151.     $p_header['mtime'$v_data['mtime'];
  4152.     if ($p_header['mdate'&& $p_header['mtime'])
  4153.     {
  4154.       // ----- Extract time
  4155.       $v_hour ($p_header['mtime'0xF800>> 11;
  4156.       $v_minute ($p_header['mtime'0x07E0>> 5;
  4157.       $v_seconde ($p_header['mtime'0x001F)*2;
  4158.  
  4159.       // ----- Extract date
  4160.       $v_year (($p_header['mdate'0xFE00>> 91980;
  4161.       $v_month ($p_header['mdate'0x01E0>> 5;
  4162.       $v_day $p_header['mdate'0x001F;
  4163.  
  4164.       // ----- Get UNIX date format
  4165.       $p_header['mtime'mktime($v_hour$v_minute$v_seconde$v_month$v_day$v_year);
  4166.  
  4167.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
  4168.     }
  4169.     else
  4170.     {
  4171.       $p_header['mtime'time();
  4172.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
  4173.     }
  4174.  
  4175.     // TBC
  4176.     //for(reset($v_data); $key = key($v_data); next($v_data)) {
  4177.     //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Attribut[$key] = ".$v_data[$key]);
  4178.     //}
  4179.  
  4180.     // ----- Set the stored filename
  4181.     $p_header['stored_filename'$p_header['filename'];
  4182.  
  4183.     // ----- Set the status field
  4184.     $p_header['status'"ok";
  4185.  
  4186.     // ----- Return
  4187.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4188.     return $v_result;
  4189.   }
  4190.   // --------------------------------------------------------------------------------
  4191.  
  4192.   // --------------------------------------------------------------------------------
  4193.   // Function : privReadCentralFileHeader()
  4194.   // Description :
  4195.   // Parameters :
  4196.   // Return Values :
  4197.   // --------------------------------------------------------------------------------
  4198.   function privReadCentralFileHeader(&$p_header)
  4199.   {
  4200.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadCentralFileHeader", "");
  4201.     $v_result=1;
  4202.  
  4203.     // ----- Read the 4 bytes signature
  4204.     $v_binary_data @fread($this->zip_fd4);
  4205.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
  4206.     $v_data unpack('Vid'$v_binary_data);
  4207.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
  4208.  
  4209.     // ----- Check signature
  4210.     if ($v_data['id'!= 0x02014b50)
  4211.     {
  4212.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid Central Dir File signature");
  4213.  
  4214.       // ----- Error log
  4215.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT'Invalid archive structure');
  4216.  
  4217.       // ----- Return
  4218.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4219.       return PclZip::errorCode();
  4220.     }
  4221.  
  4222.     // ----- Read the first 42 bytes of the header
  4223.     $v_binary_data fread($this->zip_fd42);
  4224.  
  4225.     // ----- Look for invalid block size
  4226.     if (strlen($v_binary_data!= 42)
  4227.     {
  4228.       $p_header['filename'"";
  4229.       $p_header['status'"invalid_header";
  4230.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));
  4231.  
  4232.       // ----- Error log
  4233.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT"Invalid block size : ".strlen($v_binary_data));
  4234.  
  4235.       // ----- Return
  4236.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4237.       return PclZip::errorCode();
  4238.     }
  4239.  
  4240.     // ----- Extract the values
  4241.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header : '".$v_binary_data."'");
  4242.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Header (Hex) : '".bin2hex($v_binary_data)."'");
  4243.     $p_header unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset'$v_binary_data);
  4244.  
  4245.     // ----- Get filename
  4246.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "File name length : ".$p_header['filename_len']);
  4247.     if ($p_header['filename_len'!= 0)
  4248.       $p_header['filename'fread($this->zip_fd$p_header['filename_len']);
  4249.     else
  4250.       $p_header['filename''';
  4251.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Filename : \''.$p_header['filename'].'\'');
  4252.  
  4253.     // ----- Get extra
  4254.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Extra length : ".$p_header['extra_len']);
  4255.     if ($p_header['extra_len'!= 0)
  4256.       $p_header['extra'fread($this->zip_fd$p_header['extra_len']);
  4257.     else
  4258.       $p_header['extra''';
  4259.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Extra : \''.$p_header['extra'].'\'');
  4260.  
  4261.     // ----- Get comment
  4262.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Comment length : ".$p_header['comment_len']);
  4263.     if ($p_header['comment_len'!= 0)
  4264.       $p_header['comment'fread($this->zip_fd$p_header['comment_len']);
  4265.     else
  4266.       $p_header['comment''';
  4267.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Comment : \''.$p_header['comment'].'\'');
  4268.  
  4269.     // ----- Extract properties
  4270.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version : \''.($p_header['version']/10).'.'.($p_header['version']%10).'\'');
  4271.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Version need to extract : \''.($p_header['version_extracted']/10).'.'.($p_header['version_extracted']%10).'\'');
  4272.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Size : \''.$p_header['size'].'\'');
  4273.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Compressed Size : \''.$p_header['compressed_size'].'\'');
  4274.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'CRC : \''.sprintf("0x%X", $p_header['crc']).'\'');
  4275.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Flag : \''.$p_header['flag'].'\'');
  4276.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Offset : \''.$p_header['offset'].'\'');
  4277.  
  4278.     // ----- Recuperate date in UNIX format
  4279.     if ($p_header['mdate'&& $p_header['mtime'])
  4280.     {
  4281.       // ----- Extract time
  4282.       $v_hour ($p_header['mtime'0xF800>> 11;
  4283.       $v_minute ($p_header['mtime'0x07E0>> 5;
  4284.       $v_seconde ($p_header['mtime'0x001F)*2;
  4285.  
  4286.       // ----- Extract date
  4287.       $v_year (($p_header['mdate'0xFE00>> 91980;
  4288.       $v_month ($p_header['mdate'0x01E0>> 5;
  4289.       $v_day $p_header['mdate'0x001F;
  4290.  
  4291.       // ----- Get UNIX date format
  4292.       $p_header['mtime'mktime($v_hour$v_minute$v_seconde$v_month$v_day$v_year);
  4293.  
  4294.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
  4295.     }
  4296.     else
  4297.     {
  4298.       $p_header['mtime'time();
  4299.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Date is actual : \''.date("d/m/y H:i:s", $p_header['mtime']).'\'');
  4300.     }
  4301.  
  4302.     // ----- Set the stored filename
  4303.     $p_header['stored_filename'$p_header['filename'];
  4304.  
  4305.     // ----- Set default status to ok
  4306.     $p_header['status''ok';
  4307.  
  4308.     // ----- Look if it is a directory
  4309.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Internal (Hex) : '".sprintf("Ox%04X", $p_header['internal'])."'");
  4310.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "External (Hex) : '".sprintf("Ox%04X", $p_header['external'])."' (".(($p_header['external']&0x00000010)==0x00000010?'is a folder':'is a file').')');
  4311.     if (substr($p_header['filename']-1== '/'{
  4312.       //$p_header['external'] = 0x41FF0010;
  4313.       $p_header['external'0x00000010;
  4314.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Force folder external : \''.sprintf("Ox%04X", $p_header['external']).'\'');
  4315.     }
  4316.  
  4317.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Header of filename : \''.$p_header['filename'].'\'');
  4318.  
  4319.     // ----- Return
  4320.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4321.     return $v_result;
  4322.   }
  4323.   // --------------------------------------------------------------------------------
  4324.  
  4325.   // --------------------------------------------------------------------------------
  4326.   // Function : privCheckFileHeaders()
  4327.   // Description :
  4328.   // Parameters :
  4329.   // Return Values :
  4330.   //   1 on success,
  4331.   //   0 on error;
  4332.   // --------------------------------------------------------------------------------
  4333.   function privCheckFileHeaders(&$p_local_header&$p_central_header)
  4334.   {
  4335.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFileHeaders", "");
  4336.     $v_result=1;
  4337.  
  4338.     // ----- Check the static values
  4339.     // TBC
  4340.     if ($p_local_header['filename'!= $p_central_header['filename']{
  4341.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename" : TBC To Be Completed');
  4342.     }
  4343.     if ($p_local_header['version_extracted'!= $p_central_header['version_extracted']{
  4344.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "version_extracted" : TBC To Be Completed');
  4345.     }
  4346.     if ($p_local_header['flag'!= $p_central_header['flag']{
  4347.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "flag" : TBC To Be Completed');
  4348.     }
  4349.     if ($p_local_header['compression'!= $p_central_header['compression']{
  4350.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "compression" : TBC To Be Completed');
  4351.     }
  4352.     if ($p_local_header['mtime'!= $p_central_header['mtime']{
  4353.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "mtime" : TBC To Be Completed');
  4354.     }
  4355.     if ($p_local_header['filename_len'!= $p_central_header['filename_len']{
  4356.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Bad check "filename_len" : TBC To Be Completed');
  4357.     }
  4358.  
  4359.     // ----- Look for flag bit 3
  4360.     if (($p_local_header['flag'8== 8{
  4361.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Purpose bit flag bit 3 set !');
  4362.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'File size, compression size and crc found in central header');
  4363.         $p_local_header['size'$p_central_header['size'];
  4364.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size : \''.$p_local_header['size'].'\'');
  4365.         $p_local_header['compressed_size'$p_central_header['compressed_size'];
  4366.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Compressed Size : \''.$p_local_header['compressed_size'].'\'');
  4367.         $p_local_header['crc'$p_central_header['crc'];
  4368.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'CRC : \''.sprintf("0x%X", $p_local_header['crc']).'\'');
  4369.     }
  4370.  
  4371.     // ----- Return
  4372.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4373.     return $v_result;
  4374.   }
  4375.   // --------------------------------------------------------------------------------
  4376.  
  4377.   // --------------------------------------------------------------------------------
  4378.   // Function : privReadEndCentralDir()
  4379.   // Description :
  4380.   // Parameters :
  4381.   // Return Values :
  4382.   // --------------------------------------------------------------------------------
  4383.   function privReadEndCentralDir(&$p_central_dir)
  4384.   {
  4385.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privReadEndCentralDir", "");
  4386.     $v_result=1;
  4387.  
  4388.     // ----- Go to the end of the zip file
  4389.     $v_size filesize($this->zipname);
  4390.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Size of the file :$v_size");
  4391.     @fseek($this->zip_fd$v_size);
  4392.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position at end of zip file : \''.ftell($this->zip_fd).'\'');
  4393.     if (@ftell($this->zip_fd!= $v_size)
  4394.     {
  4395.       // ----- Error log
  4396.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT'Unable to go to the end of the archive \''.$this->zipname.'\'');
  4397.  
  4398.       // ----- Return
  4399.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4400.       return PclZip::errorCode();
  4401.     }
  4402.  
  4403.     // ----- First try : look if this is an archive with no commentaries (most of the time)
  4404.     // in this case the end of central dir is at 22 bytes of the file end
  4405.     $v_found 0;
  4406.     if ($v_size 26{
  4407.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Look for central dir with no comment');
  4408.       @fseek($this->zip_fd$v_size-22);
  4409.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after min central position : \''.ftell($this->zip_fd).'\'');
  4410.       if (($v_pos @ftell($this->zip_fd)) != ($v_size-22))
  4411.       {
  4412.         // ----- Error log
  4413.         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  4414.  
  4415.         // ----- Return
  4416.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4417.         return PclZip::errorCode();
  4418.       }
  4419.  
  4420.       // ----- Read for bytes
  4421.       $v_binary_data @fread($this->zip_fd4);
  4422.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Binary data is : '".sprintf("%08x", $v_binary_data)."'");
  4423.       $v_data @unpack('Vid'$v_binary_data);
  4424.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Binary signature is : '".sprintf("0x%08x", $v_data['id'])."'");
  4425.  
  4426.       // ----- Check signature
  4427.       if ($v_data['id'== 0x06054b50{
  4428.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found central dir at the default position.");
  4429.         $v_found 1;
  4430.       }
  4431.  
  4432.       $v_pos ftell($this->zip_fd);
  4433.     }
  4434.  
  4435.     // ----- Go back to the maximum possible size of the Central Dir End Record
  4436.     if (!$v_found{
  4437.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Start extended search of end central dir');
  4438.       $v_maximum_size 65557// 0xFFFF + 22;
  4439.       if ($v_maximum_size $v_size)
  4440.         $v_maximum_size $v_size;
  4441.       @fseek($this->zip_fd$v_size-$v_maximum_size);
  4442.       if (@ftell($this->zip_fd!= ($v_size-$v_maximum_size))
  4443.       {
  4444.         // ----- Error log
  4445.         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  4446.  
  4447.         // ----- Return
  4448.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4449.         return PclZip::errorCode();
  4450.       }
  4451.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Position after max central position : \''.ftell($this->zip_fd).'\'');
  4452.  
  4453.       // ----- Read byte per byte in order to find the signature
  4454.       $v_pos ftell($this->zip_fd);
  4455.       $v_bytes 0x00000000;
  4456.       while ($v_pos $v_size)
  4457.       {
  4458.         // ----- Read a byte
  4459.         $v_byte @fread($this->zip_fd1);
  4460.  
  4461.         // -----  Add the byte
  4462.         $v_bytes ($v_bytes << 8Ord($v_byte);
  4463.  
  4464.         // ----- Compare the bytes
  4465.         if ($v_bytes == 0x504b0506)
  4466.         {
  4467.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, 'Found End Central Dir signature at position : \''.ftell($this->zip_fd).'\'');
  4468.           $v_pos++;
  4469.           break;
  4470.         }
  4471.  
  4472.         $v_pos++;
  4473.       }
  4474.  
  4475.       // ----- Look if not found end of central dir
  4476.       if ($v_pos == $v_size)
  4477.       {
  4478.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Unable to find End of Central Dir Record signature");
  4479.  
  4480.         // ----- Error log
  4481.         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT"Unable to find End of Central Dir Record signature");
  4482.  
  4483.         // ----- Return
  4484.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4485.         return PclZip::errorCode();
  4486.       }
  4487.     }
  4488.  
  4489.     // ----- Read the first 18 bytes of the header
  4490.     $v_binary_data fread($this->zip_fd18);
  4491.  
  4492.     // ----- Look for invalid block size
  4493.     if (strlen($v_binary_data!= 18)
  4494.     {
  4495.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
  4496.  
  4497.       // ----- Error log
  4498.       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT"Invalid End of Central Dir Record size : ".strlen($v_binary_data));
  4499.  
  4500.       // ----- Return
  4501.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4502.       return PclZip::errorCode();
  4503.     }
  4504.  
  4505.     // ----- Extract the values
  4506.     ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record : '".$v_binary_data."'");
  4507.     ////--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Central Dir Record (Hex) : '".bin2hex($v_binary_data)."'");
  4508.     $v_data unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size'$v_binary_data);
  4509.  
  4510.     // ----- Check the global size
  4511.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Comment length : ".$v_data['comment_size']);
  4512.     if (($v_pos $v_data['comment_size'18!= $v_size{
  4513.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The central dir is not at the end of the archive. Some trailing bytes exists after the archive.");
  4514.  
  4515.       // ----- Removed in release 2.2 see readme file
  4516.       // The check of the file size is a little too strict.
  4517.       // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
  4518.       // While decrypted, zip has training 0 bytes
  4519.       if (0{
  4520.       // ----- Error log
  4521.                            'The central dir is not at the end of the archive.'
  4522.                            .' Some trailing bytes exists after the archive.');
  4523.  
  4524.       // ----- Return
  4525.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4526.       return PclZip::errorCode();
  4527.       }
  4528.     }
  4529.  
  4530.     // ----- Get comment
  4531.     if ($v_data['comment_size'!= 0)
  4532.       $p_central_dir['comment'fread($this->zip_fd$v_data['comment_size']);
  4533.     else
  4534.       $p_central_dir['comment''';
  4535.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Comment : \''.$p_central_dir['comment'].'\'');
  4536.  
  4537.     $p_central_dir['entries'$v_data['entries'];
  4538.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries : \''.$p_central_dir['entries'].'\'');
  4539.     $p_central_dir['disk_entries'$v_data['disk_entries'];
  4540.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Nb of entries for this disk : \''.$p_central_dir['disk_entries'].'\'');
  4541.     $p_central_dir['offset'$v_data['offset'];
  4542.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Offset of Central Dir : \''.$p_central_dir['offset'].'\'');
  4543.     $p_central_dir['size'$v_data['size'];
  4544.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Size of Central Dir : \''.$p_central_dir['size'].'\'');
  4545.     $p_central_dir['disk'$v_data['disk'];
  4546.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Disk number : \''.$p_central_dir['disk'].'\'');
  4547.     $p_central_dir['disk_start'$v_data['disk_start'];
  4548.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, 'Start disk number : \''.$p_central_dir['disk_start'].'\'');
  4549.  
  4550.     // TBC
  4551.     //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
  4552.     //  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "central_dir[$key] = ".$p_central_dir[$key]);
  4553.     //}
  4554.  
  4555.     // ----- Return
  4556.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4557.     return $v_result;
  4558.   }
  4559.   // --------------------------------------------------------------------------------
  4560.  
  4561.   // --------------------------------------------------------------------------------
  4562.   // Function : privDeleteByRule()
  4563.   // Description :
  4564.   // Parameters :
  4565.   // Return Values :
  4566.   // --------------------------------------------------------------------------------
  4567.   function privDeleteByRule(&$p_result_list&$p_options)
  4568.   {
  4569.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDeleteByRule", "");
  4570.     $v_result=1;
  4571.     $v_list_detail array();
  4572.  
  4573.     // ----- Open the zip file
  4574.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  4575.     if (($v_result=$this->privOpenFd('rb')) != 1)
  4576.     {
  4577.       // ----- Return
  4578.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4579.       return $v_result;
  4580.     }
  4581.  
  4582.     // ----- Read the central directory informations
  4583.     $v_central_dir array();
  4584.     if (($v_result $this->privReadEndCentralDir($v_central_dir)) != 1)
  4585.     {
  4586.       $this->privCloseFd();
  4587.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4588.       return $v_result;
  4589.     }
  4590.  
  4591.     // ----- Go to beginning of File
  4592.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
  4593.     @rewind($this->zip_fd);
  4594.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in file : ".ftell($this->zip_fd)."'");
  4595.  
  4596.     // ----- Scan all the files
  4597.     // ----- Start at beginning of Central Dir
  4598.     $v_pos_entry $v_central_dir['offset'];
  4599.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
  4600.     @rewind($this->zip_fd);
  4601.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
  4602.     if (@fseek($this->zip_fd$v_pos_entry))
  4603.     {
  4604.       // ----- Close the zip file
  4605.       $this->privCloseFd();
  4606.  
  4607.       // ----- Error log
  4608.       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP'Invalid archive size');
  4609.  
  4610.       // ----- Return
  4611.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4612.       return PclZip::errorCode();
  4613.     }
  4614.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
  4615.  
  4616.     // ----- Read each entry
  4617.     $v_header_list array();
  4618.     $j_start 0;
  4619.     for ($i=0$v_nb_extracted=0$i<$v_central_dir['entries']$i++)
  4620.     {
  4621.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Read next file header entry (index '$i')");
  4622.  
  4623.       // ----- Read the file header
  4624.       $v_header_list[$v_nb_extractedarray();
  4625.       if (($v_result $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
  4626.       {
  4627.         // ----- Close the zip file
  4628.         $this->privCloseFd();
  4629.  
  4630.         //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4631.         return $v_result;
  4632.       }
  4633.  
  4634.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename (index '$i') : '".$v_header_list[$v_nb_extracted]['stored_filename']."'");
  4635.  
  4636.       // ----- Store the index
  4637.       $v_header_list[$v_nb_extracted]['index'$i;
  4638.  
  4639.       // ----- Look for the specific extract rules
  4640.       $v_found false;
  4641.  
  4642.       // ----- Look for extract by name rule
  4643.       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
  4644.           && ($p_options[PCLZIP_OPT_BY_NAME!= 0)) {
  4645.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByName'");
  4646.  
  4647.           // ----- Look if the filename is in the list
  4648.           for ($j=0($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found)$j++{
  4649.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Compare with file '".$p_options[PCLZIP_OPT_BY_NAME][$j]."'");
  4650.  
  4651.               // ----- Look for a directory
  4652.               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j]-1== "/"{
  4653.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The searched item is a directory");
  4654.  
  4655.                   // ----- Look if the directory is in the filename path
  4656.                   if (   (strlen($v_header_list[$v_nb_extracted]['stored_filename']strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
  4657.                       && (substr($v_header_list[$v_nb_extracted]['stored_filename']0strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  4658.                       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The directory is in the file path");
  4659.                       $v_found true;
  4660.                   }
  4661.                   elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010/* Indicates a folder */
  4662.                           && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  4663.                       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The entry is the searched directory");
  4664.                       $v_found true;
  4665.                   }
  4666.               }
  4667.               // ----- Look for a filename
  4668.               elseif ($v_header_list[$v_nb_extracted]['stored_filename'== $p_options[PCLZIP_OPT_BY_NAME][$j]{
  4669.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The file is the right one.");
  4670.                   $v_found true;
  4671.               }
  4672.           }
  4673.       }
  4674.  
  4675.       // ----- Look for extract by ereg rule
  4676.       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
  4677.                && ($p_options[PCLZIP_OPT_BY_EREG!= "")) {
  4678.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract by ereg '".$p_options[PCLZIP_OPT_BY_EREG]."'");
  4679.  
  4680.           if (ereg($p_options[PCLZIP_OPT_BY_EREG]$v_header_list[$v_nb_extracted]['stored_filename'])) {
  4681.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
  4682.               $v_found true;
  4683.           }
  4684.       }
  4685.  
  4686.       // ----- Look for extract by preg rule
  4687.       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
  4688.                && ($p_options[PCLZIP_OPT_BY_PREG!= "")) {
  4689.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByEreg'");
  4690.  
  4691.           if (preg_match($p_options[PCLZIP_OPT_BY_PREG]$v_header_list[$v_nb_extracted]['stored_filename'])) {
  4692.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Filename match the regular expression");
  4693.               $v_found true;
  4694.           }
  4695.       }
  4696.  
  4697.       // ----- Look for extract by index rule
  4698.       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
  4699.                && ($p_options[PCLZIP_OPT_BY_INDEX!= 0)) {
  4700.           //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Extract with rule 'ByIndex'");
  4701.  
  4702.           // ----- Look if the index is in the list
  4703.           for ($j=$j_start($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found)$j++{
  4704.               //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look if index '$i' is in [".$p_options[PCLZIP_OPT_BY_INDEX][$j]['start'].",".$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']."]");
  4705.  
  4706.               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']&& ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  4707.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found as part of an index range");
  4708.                   $v_found true;
  4709.               }
  4710.               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']{
  4711.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Do not look this index range for next loop");
  4712.                   $j_start $j+1;
  4713.               }
  4714.  
  4715.               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i{
  4716.                   //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Index range is greater than index, stop loop");
  4717.                   break;
  4718.               }
  4719.           }
  4720.       }
  4721.       else {
  4722.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "No argument mean remove all file");
  4723.           $v_found true;
  4724.       }
  4725.  
  4726.       // ----- Look for deletion
  4727.       if ($v_found)
  4728.       {
  4729.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' need to be deleted");
  4730.         unset($v_header_list[$v_nb_extracted]);
  4731.       }
  4732.       else
  4733.       {
  4734.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$v_header_list[$v_nb_extracted]['stored_filename']."', index '$i' will not be deleted");
  4735.         $v_nb_extracted++;
  4736.       }
  4737.     }
  4738.  
  4739.     // ----- Look if something need to be deleted
  4740.     if ($v_nb_extracted 0{
  4741.  
  4742.         // ----- Creates a temporay file
  4743.         $v_zip_temp_name PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  4744.  
  4745.         // ----- Creates a temporary zip archive
  4746.         $v_temp_zip new PclZip($v_zip_temp_name);
  4747.  
  4748.         // ----- Open the temporary zip file in write mode
  4749.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary write mode");
  4750.         if (($v_result $v_temp_zip->privOpenFd('wb')) != 1{
  4751.             $this->privCloseFd();
  4752.  
  4753.             // ----- Return
  4754.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4755.             return $v_result;
  4756.         }
  4757.  
  4758.         // ----- Look which file need to be kept
  4759.         for ($i=0$i<sizeof($v_header_list)$i++{
  4760.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Keep entry index '$i' : '".$v_header_list[$i]['filename']."'");
  4761.  
  4762.             // ----- Calculate the position of the header
  4763.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset='". $v_header_list[$i]['offset']."'");
  4764.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position before rewind : ".ftell($this->zip_fd)."'");
  4765.             @rewind($this->zip_fd);
  4766.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after rewind : ".ftell($this->zip_fd)."'");
  4767.             if (@fseek($this->zip_fd,  $v_header_list[$i]['offset'])) {
  4768.                 // ----- Close the zip file
  4769.                 $this->privCloseFd();
  4770.                 $v_temp_zip->privCloseFd();
  4771.                 @unlink($v_zip_temp_name);
  4772.  
  4773.                 // ----- Error log
  4774.                 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP'Invalid archive size');
  4775.  
  4776.                 // ----- Return
  4777.                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4778.                 return PclZip::errorCode();
  4779.             }
  4780.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position after fseek : ".ftell($this->zip_fd)."'");
  4781.  
  4782.             // ----- Read the file header
  4783.             $v_local_header array();
  4784.             if (($v_result $this->privReadFileHeader($v_local_header)) != 1{
  4785.                 // ----- Close the zip file
  4786.                 $this->privCloseFd();
  4787.                 $v_temp_zip->privCloseFd();
  4788.                 @unlink($v_zip_temp_name);
  4789.  
  4790.                 // ----- Return
  4791.                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4792.                 return $v_result;
  4793.             }
  4794.             
  4795.             // ----- Check that local file header is same as central file header
  4796.             if ($this->privCheckFileHeaders($v_local_header,
  4797.                                             $v_header_list[$i]!= 1{
  4798.                 // TBC
  4799.             }
  4800.             unset($v_local_header);
  4801.  
  4802.             // ----- Write the file header
  4803.             if (($v_result $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1{
  4804.                 // ----- Close the zip file
  4805.                 $this->privCloseFd();
  4806.                 $v_temp_zip->privCloseFd();
  4807.                 @unlink($v_zip_temp_name);
  4808.  
  4809.                 // ----- Return
  4810.                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4811.                 return $v_result;
  4812.             }
  4813.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset for this file is '".$v_header_list[$i]['offset']."'");
  4814.  
  4815.             // ----- Read/write the data block
  4816.             if (($v_result PclZipUtilCopyBlock($this->zip_fd$v_temp_zip->zip_fd$v_header_list[$i]['compressed_size'])) != 1{
  4817.                 // ----- Close the zip file
  4818.                 $this->privCloseFd();
  4819.                 $v_temp_zip->privCloseFd();
  4820.                 @unlink($v_zip_temp_name);
  4821.  
  4822.                 // ----- Return
  4823.                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4824.                 return $v_result;
  4825.             }
  4826.         }
  4827.  
  4828.         // ----- Store the offset of the central dir
  4829.         $v_offset @ftell($v_temp_zip->zip_fd);
  4830.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "New offset of central dir : $v_offset");
  4831.  
  4832.         // ----- Re-Create the Central Dir files header
  4833.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the new central directory");
  4834.         for ($i=0$i<sizeof($v_header_list)$i++{
  4835.             // ----- Create the file header
  4836.             //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Offset of file : ".$v_header_list[$i]['offset']);
  4837.             if (($v_result $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1{
  4838.                 $v_temp_zip->privCloseFd();
  4839.                 $this->privCloseFd();
  4840.                 @unlink($v_zip_temp_name);
  4841.  
  4842.                 // ----- Return
  4843.                 //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4844.                 return $v_result;
  4845.             }
  4846.  
  4847.             // ----- Transform the header to a 'usable' info
  4848.             $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i]$p_result_list[$i]);
  4849.         }
  4850.  
  4851.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Creates the central directory footer");
  4852.  
  4853.         // ----- Zip file comment
  4854.         $v_comment '';
  4855.         if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  4856.           $v_comment $p_options[PCLZIP_OPT_COMMENT];
  4857.         }
  4858.  
  4859.         // ----- Calculate the size of the central header
  4860.         $v_size @ftell($v_temp_zip->zip_fd)-$v_offset;
  4861.  
  4862.         // ----- Create the central dir footer
  4863.         if (($v_result $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list)$v_size$v_offset$v_comment)) != 1{
  4864.             // ----- Reset the file list
  4865.             unset($v_header_list);
  4866.             $v_temp_zip->privCloseFd();
  4867.             $this->privCloseFd();
  4868.             @unlink($v_zip_temp_name);
  4869.  
  4870.             // ----- Return
  4871.             //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4872.             return $v_result;
  4873.         }
  4874.  
  4875.         // ----- Close
  4876.         $v_temp_zip->privCloseFd();
  4877.         $this->privCloseFd();
  4878.  
  4879.         // ----- Delete the zip file
  4880.         // TBC : I should test the result ...
  4881.         @unlink($this->zipname);
  4882.  
  4883.         // ----- Rename the temporary file
  4884.         // TBC : I should test the result ...
  4885.         //@rename($v_zip_temp_name, $this->zipname);
  4886.         PclZipUtilRename($v_zip_temp_name$this->zipname);
  4887.     
  4888.         // ----- Destroy the temporary archive
  4889.         unset($v_temp_zip);
  4890.     }
  4891.     
  4892.     // ----- Remove every files : reset the file
  4893.     else if ($v_central_dir['entries'!= 0{
  4894.         $this->privCloseFd();
  4895.  
  4896.         if (($v_result $this->privOpenFd('wb')) != 1{
  4897.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4898.           return $v_result;
  4899.         }
  4900.  
  4901.         if (($v_result $this->privWriteCentralHeader(000'')) != 1{
  4902.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4903.           return $v_result;
  4904.         }
  4905.  
  4906.         $this->privCloseFd();
  4907.     }
  4908.  
  4909.     // ----- Return
  4910.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4911.     return $v_result;
  4912.   }
  4913.   // --------------------------------------------------------------------------------
  4914.  
  4915.   // --------------------------------------------------------------------------------
  4916.   // Function : privDirCheck()
  4917.   // Description :
  4918.   //   Check if a directory exists, if not it creates it and all the parents directory
  4919.   //   which may be useful.
  4920.   // Parameters :
  4921.   //   $p_dir : Directory path to check.
  4922.   // Return Values :
  4923.   //    1 : OK
  4924.   //   -1 : Unable to create directory
  4925.   // --------------------------------------------------------------------------------
  4926.   function privDirCheck($p_dir$p_is_dir=false)
  4927.   {
  4928.     $v_result 1;
  4929.  
  4930.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDirCheck", "entry='$p_dir', is_dir='".($p_is_dir?"true":"false")."'");
  4931.  
  4932.     // ----- Remove the final '/'
  4933.     if (($p_is_dir&& (substr($p_dir-1)=='/'))
  4934.     {
  4935.       $p_dir substr($p_dir0strlen($p_dir)-1);
  4936.     }
  4937.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Looking for entry '$p_dir'");
  4938.  
  4939.     // ----- Check the directory availability
  4940.     if ((is_dir($p_dir)) || ($p_dir == ""))
  4941.     {
  4942.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory");
  4943.       return 1;
  4944.     }
  4945.  
  4946.     // ----- Extract parent directory
  4947.     $p_parent_dir dirname($p_dir);
  4948.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");
  4949.  
  4950.     // ----- Just a check
  4951.     if ($p_parent_dir != $p_dir)
  4952.     {
  4953.       // ----- Look for parent directory
  4954.       if ($p_parent_dir != "")
  4955.       {
  4956.         if (($v_result $this->privDirCheck($p_parent_dir)) != 1)
  4957.         {
  4958.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  4959.           return $v_result;
  4960.         }
  4961.       }
  4962.     }
  4963.  
  4964.     // ----- Create the directory
  4965.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");
  4966.     if (!@mkdir($p_dir0777))
  4967.     {
  4968.       // ----- Error log
  4969.       PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL"Unable to create directory '$p_dir'");
  4970.  
  4971.       // ----- Return
  4972.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  4973.       return PclZip::errorCode();
  4974.     }
  4975.  
  4976.     // ----- Return
  4977.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");
  4978.     return $v_result;
  4979.   }
  4980.   // --------------------------------------------------------------------------------
  4981.  
  4982.   // --------------------------------------------------------------------------------
  4983.   // Function : privMerge()
  4984.   // Description :
  4985.   //   If $p_archive_to_add does not exist, the function exit with a success result.
  4986.   // Parameters :
  4987.   // Return Values :
  4988.   // --------------------------------------------------------------------------------
  4989.   function privMerge(&$p_archive_to_add)
  4990.   {
  4991.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privMerge", "archive='".$p_archive_to_add->zipname."'");
  4992.     $v_result=1;
  4993.  
  4994.     // ----- Look if the archive_to_add exists
  4995.     if (!is_file($p_archive_to_add->zipname))
  4996.     {
  4997.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to add does not exist. End of merge.");
  4998.  
  4999.       // ----- Nothing to merge, so merge is a success
  5000.       $v_result 1;
  5001.  
  5002.       // ----- Return
  5003.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5004.       return $v_result;
  5005.     }
  5006.  
  5007.     // ----- Look if the archive exists
  5008.     if (!is_file($this->zipname))
  5009.     {
  5010.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive does not exist, duplicate the archive_to_add.");
  5011.  
  5012.       // ----- Do a duplicate
  5013.       $v_result $this->privDuplicate($p_archive_to_add->zipname);
  5014.  
  5015.       // ----- Return
  5016.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5017.       return $v_result;
  5018.     }
  5019.  
  5020.     // ----- Open the zip file
  5021.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  5022.     if (($v_result=$this->privOpenFd('rb')) != 1)
  5023.     {
  5024.       // ----- Return
  5025.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5026.       return $v_result;
  5027.     }
  5028.  
  5029.     // ----- Read the central directory informations
  5030.     $v_central_dir array();
  5031.     if (($v_result $this->privReadEndCentralDir($v_central_dir)) != 1)
  5032.     {
  5033.       $this->privCloseFd();
  5034.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5035.       return $v_result;
  5036.     }
  5037.  
  5038.     // ----- Go to beginning of File
  5039.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");
  5040.     @rewind($this->zip_fd);
  5041.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in zip : ".ftell($this->zip_fd)."'");
  5042.  
  5043.     // ----- Open the archive_to_add file
  5044.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open archive_to_add in binary read mode");
  5045.     if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
  5046.     {
  5047.       $this->privCloseFd();
  5048.  
  5049.       // ----- Return
  5050.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5051.       return $v_result;
  5052.     }
  5053.  
  5054.     // ----- Read the central directory informations
  5055.     $v_central_dir_to_add array();
  5056.     if (($v_result $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
  5057.     {
  5058.       $this->privCloseFd();
  5059.       $p_archive_to_add->privCloseFd();
  5060.  
  5061.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5062.       return $v_result;
  5063.     }
  5064.  
  5065.     // ----- Go to beginning of File
  5066.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");
  5067.     @rewind($p_archive_to_add->zip_fd);
  5068.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Position in archive_to_add : ".ftell($p_archive_to_add->zip_fd)."'");
  5069.  
  5070.     // ----- Creates a temporay file
  5071.     $v_zip_temp_name PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  5072.  
  5073.     // ----- Open the temporary file in write mode
  5074.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  5075.     if (($v_zip_temp_fd @fopen($v_zip_temp_name'wb')) == 0)
  5076.     {
  5077.       $this->privCloseFd();
  5078.       $p_archive_to_add->privCloseFd();
  5079.  
  5080.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
  5081.  
  5082.       // ----- Return
  5083.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  5084.       return PclZip::errorCode();
  5085.     }
  5086.  
  5087.     // ----- Copy the files from the archive to the temporary file
  5088.     // TBC : Here I should better append the file and go back to erase the central dir
  5089.     $v_size $v_central_dir['offset'];
  5090.     while ($v_size != 0)
  5091.     {
  5092.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  5093.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5094.       $v_buffer fread($this->zip_fd$v_read_size);
  5095.       @fwrite($v_zip_temp_fd$v_buffer$v_read_size);
  5096.       $v_size -= $v_read_size;
  5097.     }
  5098.  
  5099.     // ----- Copy the files from the archive_to_add into the temporary file
  5100.     $v_size $v_central_dir_to_add['offset'];
  5101.     while ($v_size != 0)
  5102.     {
  5103.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  5104.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5105.       $v_buffer fread($p_archive_to_add->zip_fd$v_read_size);
  5106.       @fwrite($v_zip_temp_fd$v_buffer$v_read_size);
  5107.       $v_size -= $v_read_size;
  5108.     }
  5109.  
  5110.     // ----- Store the offset of the central dir
  5111.     $v_offset @ftell($v_zip_temp_fd);
  5112.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "New offset of central dir : $v_offset");
  5113.  
  5114.     // ----- Copy the block of file headers from the old archive
  5115.     $v_size $v_central_dir['size'];
  5116.     while ($v_size != 0)
  5117.     {
  5118.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  5119.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5120.       $v_buffer @fread($this->zip_fd$v_read_size);
  5121.       @fwrite($v_zip_temp_fd$v_buffer$v_read_size);
  5122.       $v_size -= $v_read_size;
  5123.     }
  5124.  
  5125.     // ----- Copy the block of file headers from the archive_to_add
  5126.     $v_size $v_central_dir_to_add['size'];
  5127.     while ($v_size != 0)
  5128.     {
  5129.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  5130.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5131.       $v_buffer @fread($p_archive_to_add->zip_fd$v_read_size);
  5132.       @fwrite($v_zip_temp_fd$v_buffer$v_read_size);
  5133.       $v_size -= $v_read_size;
  5134.     }
  5135.  
  5136.     // ----- Merge the file comments
  5137.     $v_comment $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
  5138.  
  5139.     // ----- Calculate the size of the (new) central header
  5140.     $v_size @ftell($v_zip_temp_fd)-$v_offset;
  5141.  
  5142.     // ----- Swap the file descriptor
  5143.     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
  5144.     // the following methods on the temporary fil and not the real archive fd
  5145.     $v_swap $this->zip_fd;
  5146.     $this->zip_fd = $v_zip_temp_fd;
  5147.     $v_zip_temp_fd $v_swap;
  5148.  
  5149.     // ----- Create the central dir footer
  5150.     if (($v_result $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries']$v_size$v_offset$v_comment)) != 1)
  5151.     {
  5152.       $this->privCloseFd();
  5153.       $p_archive_to_add->privCloseFd();
  5154.       @fclose($v_zip_temp_fd);
  5155.       $this->zip_fd = null;
  5156.  
  5157.       // ----- Reset the file list
  5158.       unset($v_header_list);
  5159.  
  5160.       // ----- Return
  5161.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5162.       return $v_result;
  5163.     }
  5164.  
  5165.     // ----- Swap back the file descriptor
  5166.     $v_swap $this->zip_fd;
  5167.     $this->zip_fd = $v_zip_temp_fd;
  5168.     $v_zip_temp_fd $v_swap;
  5169.  
  5170.     // ----- Close
  5171.     $this->privCloseFd();
  5172.     $p_archive_to_add->privCloseFd();
  5173.  
  5174.     // ----- Close the temporary file
  5175.     @fclose($v_zip_temp_fd);
  5176.  
  5177.     // ----- Delete the zip file
  5178.     // TBC : I should test the result ...
  5179.     @unlink($this->zipname);
  5180.  
  5181.     // ----- Rename the temporary file
  5182.     // TBC : I should test the result ...
  5183.     //@rename($v_zip_temp_name, $this->zipname);
  5184.     PclZipUtilRename($v_zip_temp_name$this->zipname);
  5185.  
  5186.     // ----- Return
  5187.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5188.     return $v_result;
  5189.   }
  5190.   // --------------------------------------------------------------------------------
  5191.  
  5192.   // --------------------------------------------------------------------------------
  5193.   // Function : privDuplicate()
  5194.   // Description :
  5195.   // Parameters :
  5196.   // Return Values :
  5197.   // --------------------------------------------------------------------------------
  5198.   function privDuplicate($p_archive_filename)
  5199.   {
  5200.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privDuplicate", "archive_filename='$p_archive_filename'");
  5201.     $v_result=1;
  5202.  
  5203.     // ----- Look if the $p_archive_filename exists
  5204.     if (!is_file($p_archive_filename))
  5205.     {
  5206.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Archive to duplicate does not exist. End of duplicate.");
  5207.  
  5208.       // ----- Nothing to duplicate, so duplicate is a success.
  5209.       $v_result 1;
  5210.  
  5211.       // ----- Return
  5212.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5213.       return $v_result;
  5214.     }
  5215.  
  5216.     // ----- Open the zip file
  5217.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  5218.     if (($v_result=$this->privOpenFd('wb')) != 1)
  5219.     {
  5220.       // ----- Return
  5221.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5222.       return $v_result;
  5223.     }
  5224.  
  5225.     // ----- Open the temporary file in write mode
  5226.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  5227.     if (($v_zip_temp_fd @fopen($p_archive_filename'rb')) == 0)
  5228.     {
  5229.       $this->privCloseFd();
  5230.  
  5231.       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
  5232.  
  5233.       // ----- Return
  5234.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  5235.       return PclZip::errorCode();
  5236.     }
  5237.  
  5238.     // ----- Copy the files from the archive to the temporary file
  5239.     // TBC : Here I should better append the file and go back to erase the central dir
  5240.     $v_size filesize($p_archive_filename);
  5241.     while ($v_size != 0)
  5242.     {
  5243.       $v_read_size ($v_size PCLZIP_READ_BLOCK_SIZE $v_size PCLZIP_READ_BLOCK_SIZE);
  5244.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Read $v_read_size bytes");
  5245.       $v_buffer fread($v_zip_temp_fd$v_read_size);
  5246.       @fwrite($this->zip_fd$v_buffer$v_read_size);
  5247.       $v_size -= $v_read_size;
  5248.     }
  5249.  
  5250.     // ----- Close
  5251.     $this->privCloseFd();
  5252.  
  5253.     // ----- Close the temporary file
  5254.     @fclose($v_zip_temp_fd);
  5255.  
  5256.     // ----- Return
  5257.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5258.     return $v_result;
  5259.   }
  5260.   // --------------------------------------------------------------------------------
  5261.  
  5262.   // --------------------------------------------------------------------------------
  5263.   // Function : privErrorLog()
  5264.   // Description :
  5265.   // Parameters :
  5266.   // --------------------------------------------------------------------------------
  5267.   function privErrorLog($p_error_code=0$p_error_string='')
  5268.   {
  5269.     if (PCLZIP_ERROR_EXTERNAL == 1{
  5270.       PclError($p_error_code$p_error_string);
  5271.     }
  5272.     else {
  5273.       $this->error_code = $p_error_code;
  5274.       $this->error_string = $p_error_string;
  5275.     }
  5276.   }
  5277.   // --------------------------------------------------------------------------------
  5278.  
  5279.   // --------------------------------------------------------------------------------
  5280.   // Function : privErrorReset()
  5281.   // Description :
  5282.   // Parameters :
  5283.   // --------------------------------------------------------------------------------
  5284.   function privErrorReset()
  5285.   {
  5286.     if (PCLZIP_ERROR_EXTERNAL == 1{
  5287.       PclErrorReset();
  5288.     }
  5289.     else {
  5290.       $this->error_code = 0;
  5291.       $this->error_string = '';
  5292.     }
  5293.   }
  5294.   // --------------------------------------------------------------------------------
  5295.  
  5296.   // --------------------------------------------------------------------------------
  5297.   // Function : privDecrypt()
  5298.   // Description :
  5299.   // Parameters :
  5300.   // Return Values :
  5301.   // --------------------------------------------------------------------------------
  5302.   function privDecrypt($p_encryption_header&$p_buffer$p_size$p_crc)
  5303.   {
  5304.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDecrypt', "size=".$p_size."");
  5305.     $v_result=1;
  5306.     
  5307.     // ----- To Be Modified ;-)
  5308.     $v_pwd "test";
  5309.     
  5310.     $p_buffer PclZipUtilZipDecrypt($p_buffer$p_size$p_encryption_header,
  5311.                                      $p_crc$v_pwd);
  5312.     
  5313.     // ----- Return
  5314.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5315.     return $v_result;
  5316.   }
  5317.   // --------------------------------------------------------------------------------
  5318.  
  5319.   // --------------------------------------------------------------------------------
  5320.   // Function : privDisableMagicQuotes()
  5321.   // Description :
  5322.   // Parameters :
  5323.   // Return Values :
  5324.   // --------------------------------------------------------------------------------
  5325.   function privDisableMagicQuotes()
  5326.   {
  5327.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privDisableMagicQuotes', "");
  5328.     $v_result=1;
  5329.  
  5330.     // ----- Look if function exists
  5331.     if (   (!function_exists("get_magic_quotes_runtime"))
  5332.         || (!function_exists("set_magic_quotes_runtime"))) {
  5333.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");
  5334.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5335.       return $v_result;
  5336.     }
  5337.  
  5338.     // ----- Look if already done
  5339.     if ($this->magic_quotes_status != -1{
  5340.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote already disabled");
  5341.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5342.       return $v_result;
  5343.     }
  5344.  
  5345.     // ----- Get and memorize the magic_quote value
  5346.     //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Current magic_quotes_runtime status is '".($this->magic_quotes_status==0?'disable':'enable')."'");
  5347.  
  5348.     // ----- Disable magic_quotes
  5349.     if ($this->magic_quotes_status == 1{
  5350.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Disable magic_quotes");
  5351.       @set_magic_quotes_runtime(0);
  5352.     }
  5353.  
  5354.     // ----- Return
  5355.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5356.     return $v_result;
  5357.   }
  5358.   // --------------------------------------------------------------------------------
  5359.  
  5360.   // --------------------------------------------------------------------------------
  5361.   // Function : privSwapBackMagicQuotes()
  5362.   // Description :
  5363.   // Parameters :
  5364.   // Return Values :
  5365.   // --------------------------------------------------------------------------------
  5366.   function privSwapBackMagicQuotes()
  5367.   {
  5368.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privSwapBackMagicQuotes', "");
  5369.     $v_result=1;
  5370.  
  5371.     // ----- Look if function exists
  5372.     if (   (!function_exists("get_magic_quotes_runtime"))
  5373.         || (!function_exists("set_magic_quotes_runtime"))) {
  5374.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Functions *et_magic_quotes_runtime are not supported");
  5375.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5376.       return $v_result;
  5377.     }
  5378.  
  5379.     // ----- Look if something to do
  5380.     if ($this->magic_quotes_status != -1{
  5381.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "magic_quote not modified");
  5382.       //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5383.       return $v_result;
  5384.     }
  5385.  
  5386.     // ----- Swap back magic_quotes
  5387.     if ($this->magic_quotes_status == 1{
  5388.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Enable back magic_quotes");
  5389.     }
  5390.  
  5391.     // ----- Return
  5392.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5393.     return $v_result;
  5394.   }
  5395.   // --------------------------------------------------------------------------------
  5396.  
  5397.   }
  5398.   // End of class
  5399.   // --------------------------------------------------------------------------------
  5400.  
  5401.   // --------------------------------------------------------------------------------
  5402.   // Function : PclZipUtilPathReduction()
  5403.   // Description :
  5404.   // Parameters :
  5405.   // Return Values :
  5406.   // --------------------------------------------------------------------------------
  5407.   function PclZipUtilPathReduction($p_dir)
  5408.   {
  5409.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathReduction", "dir='$p_dir'");
  5410.     $v_result "";
  5411.  
  5412.     // ----- Look for not empty path
  5413.     if ($p_dir != ""{
  5414.       // ----- Explode path by directory names
  5415.       $v_list explode("/"$p_dir);
  5416.  
  5417.       // ----- Study directories from last to first
  5418.       $v_skip 0;
  5419.       for ($i=sizeof($v_list)-1$i>=0$i--{
  5420.         // ----- Look for current path
  5421.         if ($v_list[$i== "."{
  5422.           // ----- Ignore this directory
  5423.           // Should be the first $i=0, but no check is done
  5424.         }
  5425.         else if ($v_list[$i== ".."{
  5426.           $v_skip++;
  5427.         }
  5428.         else if ($v_list[$i== ""{
  5429.           // ----- First '/' i.e. root slash
  5430.           if ($i == 0{
  5431.             $v_result "/".$v_result;
  5432.             if ($v_skip 0{
  5433.                 // ----- It is an invalid path, so the path is not modified
  5434.                 // TBC
  5435.                 $v_result $p_dir;
  5436.                 //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Invalid path is unchanged");
  5437.                 $v_skip 0;
  5438.             }
  5439.           }
  5440.           // ----- Last '/' i.e. indicates a directory
  5441.           else if ($i == (sizeof($v_list)-1)) {
  5442.             $v_result $v_list[$i];
  5443.           }
  5444.           // ----- Double '/' inside the path
  5445.           else {
  5446.             // ----- Ignore only the double '//' in path,
  5447.             // but not the first and last '/'
  5448.           }
  5449.         }
  5450.         else {
  5451.           // ----- Look for item to skip
  5452.           if ($v_skip 0{
  5453.             $v_skip--;
  5454.           }
  5455.           else {
  5456.             $v_result $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
  5457.           }
  5458.         }
  5459.       }
  5460.       
  5461.       // ----- Look for skip
  5462.       if ($v_skip 0{
  5463.         while ($v_skip 0{
  5464.             $v_result '../'.$v_result;
  5465.             $v_skip--;
  5466.         }
  5467.       }
  5468.     }
  5469.  
  5470.     // ----- Return
  5471.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5472.     return $v_result;
  5473.   }
  5474.   // --------------------------------------------------------------------------------
  5475.  
  5476.   // --------------------------------------------------------------------------------
  5477.   // Function : PclZipUtilPathInclusion()
  5478.   // Description :
  5479.   //   This function indicates if the path $p_path is under the $p_dir tree. Or,
  5480.   //   said in an other way, if the file or sub-dir $p_path is inside the dir
  5481.   //   $p_dir.
  5482.   //   The function indicates also if the path is exactly the same as the dir.
  5483.   //   This function supports path with duplicated '/' like '//', but does not
  5484.   //   support '.' or '..' statements.
  5485.   // Parameters :
  5486.   // Return Values :
  5487.   //   0 if $p_path is not inside directory $p_dir
  5488.   //   1 if $p_path is inside directory $p_dir
  5489.   //   2 if $p_path is exactly the same as $p_dir
  5490.   // --------------------------------------------------------------------------------
  5491.   function PclZipUtilPathInclusion($p_dir$p_path)
  5492.   {
  5493.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilPathInclusion", "dir='$p_dir', path='$p_path'");
  5494.     $v_result 1;
  5495.     
  5496.     // ----- Look for path beginning by ./
  5497.     if (   ($p_dir == '.')
  5498.         || ((strlen($p_dir>=2&& (substr($p_dir02== './'))) {
  5499.       $p_dir PclZipUtilTranslateWinPath(getcwd()FALSE).'/'.substr($p_dir1);
  5500.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_dir '".$p_dir."'");
  5501.     }
  5502.     if (   ($p_path == '.')
  5503.         || ((strlen($p_path>=2&& (substr($p_path02== './'))) {
  5504.       $p_path PclZipUtilTranslateWinPath(getcwd()FALSE).'/'.substr($p_path1);
  5505.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Replacing ./ by full path in p_path '".$p_path."'");
  5506.     }
  5507.  
  5508.     // ----- Explode dir and path by directory separator
  5509.     $v_list_dir explode("/"$p_dir);
  5510.     $v_list_dir_size sizeof($v_list_dir);
  5511.     $v_list_path explode("/"$p_path);
  5512.     $v_list_path_size sizeof($v_list_path);
  5513.  
  5514.     // ----- Study directories paths
  5515.     $i 0;
  5516.     $j 0;
  5517.     while (($i $v_list_dir_size&& ($j $v_list_path_size&& ($v_result)) {
  5518.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Working on dir($i)='".$v_list_dir[$i]."' and path($j)='".$v_list_path[$j]."'");
  5519.  
  5520.       // ----- Look for empty dir (path reduction)
  5521.       if ($v_list_dir[$i== ''{
  5522.         $i++;
  5523.         continue;
  5524.       }
  5525.       if ($v_list_path[$j== ''{
  5526.         $j++;
  5527.         continue;
  5528.       }
  5529.  
  5530.       // ----- Compare the items
  5531.       if (($v_list_dir[$i!= $v_list_path[$j]&& ($v_list_dir[$i!= ''&& $v_list_path[$j!= ''))  {
  5532.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Items ($i,$j) are different");
  5533.         $v_result 0;
  5534.       }
  5535.  
  5536.       // ----- Next items
  5537.       $i++;
  5538.       $j++;
  5539.     }
  5540.  
  5541.     // ----- Look if everything seems to be the same
  5542.     if ($v_result{
  5543.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Look for tie break");
  5544.       // ----- Skip all the empty items
  5545.       while (($j $v_list_path_size&& ($v_list_path[$j== '')) $j++;
  5546.       while (($i $v_list_dir_size&& ($v_list_dir[$i== '')) $i++;
  5547.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Looking on dir($i)='".($i < $v_list_dir_size?$v_list_dir[$i]:'')."' and path($j)='".($j < $v_list_path_size?$v_list_path[$j]:'')."'");
  5548.  
  5549.       if (($i >= $v_list_dir_size&& ($j >= $v_list_path_size)) {
  5550.         // ----- There are exactly the same
  5551.         $v_result 2;
  5552.       }
  5553.       else if ($i $v_list_dir_size{
  5554.         // ----- The path is shorter than the dir
  5555.         $v_result 0;
  5556.       }
  5557.     }
  5558.  
  5559.     // ----- Return
  5560.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5561.     return $v_result;
  5562.   }
  5563.   // --------------------------------------------------------------------------------
  5564.  
  5565.   // --------------------------------------------------------------------------------
  5566.   // Function : PclZipUtilCopyBlock()
  5567.   // Description :
  5568.   // Parameters :
  5569.   //   $p_mode : read/write compression mode
  5570.   //             0 : src & dest normal
  5571.   //             1 : src gzip, dest normal
  5572.   //             2 : src normal, dest gzip
  5573.   //             3 : src & dest gzip
  5574.   // Return Values :
  5575.   // --------------------------------------------------------------------------------
  5576.   function PclZipUtilCopyBlock($p_src$p_dest$p_size$p_mode=0)
  5577.   {
  5578.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilCopyBlock", "size=$p_size, mode=$p_mode");
  5579.     $v_result 1;
  5580.  
  5581.     if ($p_mode==0)
  5582.     {
  5583.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset before read :".(@ftell($p_src)));
  5584.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset before write :".(@ftell($p_dest)));
  5585.       while ($p_size != 0)
  5586.       {
  5587.         $v_read_size ($p_size PCLZIP_READ_BLOCK_SIZE $p_size PCLZIP_READ_BLOCK_SIZE);
  5588.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5589.         $v_buffer @fread($p_src$v_read_size);
  5590.         @fwrite($p_dest$v_buffer$v_read_size);
  5591.         $p_size -= $v_read_size;
  5592.       }
  5593.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Src offset after read :".(@ftell($p_src)));
  5594.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Dest offset after write :".(@ftell($p_dest)));
  5595.     }
  5596.     else if ($p_mode==1)
  5597.     {
  5598.       while ($p_size != 0)
  5599.       {
  5600.         $v_read_size ($p_size PCLZIP_READ_BLOCK_SIZE $p_size PCLZIP_READ_BLOCK_SIZE);
  5601.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5602.         $v_buffer @gzread($p_src$v_read_size);
  5603.         @fwrite($p_dest$v_buffer$v_read_size);
  5604.         $p_size -= $v_read_size;
  5605.       }
  5606.     }
  5607.     else if ($p_mode==2)
  5608.     {
  5609.       while ($p_size != 0)
  5610.       {
  5611.         $v_read_size ($p_size PCLZIP_READ_BLOCK_SIZE $p_size PCLZIP_READ_BLOCK_SIZE);
  5612.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5613.         $v_buffer @fread($p_src$v_read_size);
  5614.         @gzwrite($p_dest$v_buffer$v_read_size);
  5615.         $p_size -= $v_read_size;
  5616.       }
  5617.     }
  5618.     else if ($p_mode==3)
  5619.     {
  5620.       while ($p_size != 0)
  5621.       {
  5622.         $v_read_size ($p_size PCLZIP_READ_BLOCK_SIZE $p_size PCLZIP_READ_BLOCK_SIZE);
  5623.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Read $v_read_size bytes");
  5624.         $v_buffer @gzread($p_src$v_read_size);
  5625.         @gzwrite($p_dest$v_buffer$v_read_size);
  5626.         $p_size -= $v_read_size;
  5627.       }
  5628.     }
  5629.  
  5630.     // ----- Return
  5631.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5632.     return $v_result;
  5633.   }
  5634.   // --------------------------------------------------------------------------------
  5635.  
  5636.   // --------------------------------------------------------------------------------
  5637.   // Function : PclZipUtilRename()
  5638.   // Description :
  5639.   //   This function tries to do a simple rename() function. If it fails, it
  5640.   //   tries to copy the $p_src file in a new $p_dest file and then unlink the
  5641.   //   first one.
  5642.   // Parameters :
  5643.   //   $p_src : Old filename
  5644.   //   $p_dest : New filename
  5645.   // Return Values :
  5646.   //   1 on success, 0 on failure.
  5647.   // --------------------------------------------------------------------------------
  5648.   function PclZipUtilRename($p_src$p_dest)
  5649.   {
  5650.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilRename", "source=$p_src, destination=$p_dest");
  5651.     $v_result 1;
  5652.  
  5653.     // ----- Try to rename the files
  5654.     if (!@rename($p_src$p_dest)) {
  5655.       //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to rename file, try copy+unlink");
  5656.  
  5657.       // ----- Try to copy & unlink the src
  5658.       if (!@copy($p_src$p_dest)) {
  5659.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to copy file");
  5660.         $v_result 0;
  5661.       }
  5662.       else if (!@unlink($p_src)) {
  5663.         //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 5, "Fail to unlink old filename");
  5664.         $v_result 0;
  5665.       }
  5666.     }
  5667.  
  5668.     // ----- Return
  5669.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5670.     return $v_result;
  5671.   }
  5672.   // --------------------------------------------------------------------------------
  5673.  
  5674.   // --------------------------------------------------------------------------------
  5675.   // Function : PclZipUtilOptionText()
  5676.   // Description :
  5677.   //   Translate option value in text. Mainly for debug purpose.
  5678.   // Parameters :
  5679.   //   $p_option : the option value.
  5680.   // Return Values :
  5681.   //   The option text value.
  5682.   // --------------------------------------------------------------------------------
  5683.   function PclZipUtilOptionText($p_option)
  5684.   {
  5685.     //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZipUtilOptionText", "option='".$p_option."'");
  5686.     
  5687.     $v_list get_defined_constants();
  5688.     for (reset($v_list)$v_key key($v_list)next($v_list)) {
  5689.       $v_prefix substr($v_key010);
  5690.       if ((   ($v_prefix == 'PCLZIP_OPT')
  5691.          || ($v_prefix == 'PCLZIP_CB_')
  5692.          || ($v_prefix == 'PCLZIP_ATT'))
  5693.           && ($v_list[$v_key== $p_option)) {
  5694.           //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_key);
  5695.           return $v_key;
  5696.         }
  5697.     }
  5698.     
  5699.     $v_result 'Unknown';
  5700.  
  5701.     //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  5702.     return $v_result;
  5703.   }
  5704.   // --------------------------------------------------------------------------------
  5705.  
  5706.   // --------------------------------------------------------------------------------
  5707.   // Function : PclZipUtilTranslateWinPath()
  5708.   // Description :
  5709.   //   Translate windows path by replacing '\' by '/' and optionally removing
  5710.   //   drive letter.
  5711.   // Parameters :
  5712.   //   $p_path : path to translate.
  5713.   //   $p_remove_disk_letter : true | false
  5714.   // Return Values :
  5715.   //   The path translated.
  5716.   // --------------------------------------------------------------------------------
  5717.   function PclZipUtilTranslateWinPath($p_path$p_remove_disk_letter=true)
  5718.   {
  5719.     if (stristr(php_uname()'windows')) {
  5720.       // ----- Look for potential disk letter
  5721.       if (($p_remove_disk_letter&& (($v_position strpos($p_path':')) != false)) {
  5722.           $p_path substr($p_path$v_position+1);
  5723.       }
  5724.       // ----- Change potential windows directory separator
  5725.       if ((strpos($p_path'\\'0|| (substr($p_path0,1== '\\')) {
  5726.           $p_path strtr($p_path'\\''/');
  5727.       }
  5728.     }
  5729.     return $p_path;
  5730.   }
  5731.   // --------------------------------------------------------------------------------
  5732.  
  5733.  
  5734. ?>

Documentation generated on Mon, 05 May 2008 16:22:09 +0400 by phpDocumentor 1.4.0